2026-04-09 00:03:41 +05:30
|
|
|
"use client";
|
|
|
|
|
|
2026-05-20 02:02:42 +05:30
|
|
|
import { ChevronDown, ClipboardCopy, Download, Info } from "lucide-react";
|
2026-04-09 00:03:41 +05:30
|
|
|
import { toast } from "sonner";
|
2026-04-09 18:10:34 +05:30
|
|
|
import { PlateEditor } from "@/components/editor/plate-editor";
|
2026-04-09 15:06:35 +05:30
|
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
2026-04-09 00:03:41 +05:30
|
|
|
import { Button } from "@/components/ui/button";
|
2026-04-10 12:52:27 +05:30
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
2026-04-09 00:03:41 +05:30
|
|
|
import { Spinner } from "@/components/ui/spinner";
|
2026-05-20 03:17:05 +05:30
|
|
|
import { getMemoryLimitState, useTeamMemory } from "@/hooks/use-memory";
|
2026-04-10 00:21:55 +05:30
|
|
|
|
2026-04-09 00:03:41 +05:30
|
|
|
interface TeamMemoryManagerProps {
|
|
|
|
|
searchSpaceId: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function TeamMemoryManager({ searchSpaceId }: TeamMemoryManagerProps) {
|
2026-05-20 03:17:05 +05:30
|
|
|
const { memory, displayMemory, limits, loading, saving, reset } = useTeamMemory(searchSpaceId);
|
2026-04-10 15:23:04 +05:30
|
|
|
|
2026-04-10 00:21:55 +05:30
|
|
|
const handleClear = async () => {
|
2026-04-09 00:03:41 +05:30
|
|
|
try {
|
2026-05-20 02:02:42 +05:30
|
|
|
await reset();
|
2026-04-10 00:21:55 +05:30
|
|
|
toast.success("Team memory cleared");
|
2026-04-09 00:03:41 +05:30
|
|
|
} catch {
|
2026-04-10 00:21:55 +05:30
|
|
|
toast.error("Failed to clear team memory");
|
2026-04-09 00:03:41 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-10 12:52:27 +05:30
|
|
|
const handleDownload = () => {
|
2026-04-10 02:31:59 +05:30
|
|
|
if (!memory) return;
|
|
|
|
|
try {
|
|
|
|
|
const blob = new Blob([memory], { type: "text/markdown;charset=utf-8" });
|
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
const a = document.createElement("a");
|
|
|
|
|
a.href = url;
|
|
|
|
|
a.download = "team-memory.md";
|
|
|
|
|
document.body.appendChild(a);
|
|
|
|
|
a.click();
|
|
|
|
|
document.body.removeChild(a);
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
} catch {
|
2026-04-10 12:52:27 +05:30
|
|
|
toast.error("Failed to download team memory");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleCopyMarkdown = async () => {
|
|
|
|
|
if (!memory) return;
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(memory);
|
|
|
|
|
toast.success("Copied to clipboard");
|
|
|
|
|
} catch {
|
|
|
|
|
toast.error("Failed to copy team memory");
|
2026-04-10 02:31:59 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-09 00:03:41 +05:30
|
|
|
const charCount = memory.length;
|
2026-05-20 03:17:05 +05:30
|
|
|
const limitState = getMemoryLimitState(charCount, limits);
|
2026-04-09 00:03:41 +05:30
|
|
|
|
|
|
|
|
const getCounterColor = () => {
|
2026-05-20 03:17:05 +05:30
|
|
|
if (limitState.level === "error") return "text-red-500";
|
|
|
|
|
if (limitState.level === "warning") return "text-orange-500";
|
2026-04-09 00:03:41 +05:30
|
|
|
return "text-muted-foreground";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-center py-12">
|
|
|
|
|
<Spinner size="md" className="text-muted-foreground" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 00:29:53 +05:30
|
|
|
if (!memory) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center py-16 text-center">
|
|
|
|
|
<h3 className="text-base font-medium text-foreground">
|
|
|
|
|
What does SurfSense remember about your team?
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="mt-2 max-w-sm text-sm text-muted-foreground">
|
|
|
|
|
Nothing yet. SurfSense picks up on team decisions and conventions as your team chats.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 00:03:41 +05:30
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
2026-05-18 23:46:16 +05:30
|
|
|
<Alert>
|
|
|
|
|
<Info />
|
|
|
|
|
<AlertDescription>
|
2026-04-09 18:10:34 +05:30
|
|
|
<p>
|
|
|
|
|
SurfSense uses this shared memory to provide team-wide context across all conversations
|
2026-04-10 19:07:35 +05:30
|
|
|
in this search space.
|
2026-04-09 18:10:34 +05:30
|
|
|
</p>
|
2026-04-09 15:06:35 +05:30
|
|
|
</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
|
2026-04-10 12:52:27 +05:30
|
|
|
<div className="relative h-[380px] rounded-lg border bg-background">
|
|
|
|
|
<div className="h-full overflow-y-auto scrollbar-thin">
|
|
|
|
|
<PlateEditor
|
|
|
|
|
markdown={displayMemory}
|
|
|
|
|
readOnly
|
|
|
|
|
preset="readonly"
|
|
|
|
|
variant="default"
|
|
|
|
|
editorVariant="none"
|
|
|
|
|
className="px-5 py-4 text-sm min-h-full"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-04-09 15:06:35 +05:30
|
|
|
</div>
|
|
|
|
|
|
2026-04-10 12:52:27 +05:30
|
|
|
<div className="flex items-center justify-between gap-2">
|
2026-05-20 03:17:05 +05:30
|
|
|
<span className={`text-xs shrink-0 ${getCounterColor()}`}>{limitState.label}</span>
|
2026-04-10 12:52:27 +05:30
|
|
|
<div className="flex items-center gap-1.5 sm:gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="destructive"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="text-xs sm:text-sm"
|
|
|
|
|
onClick={handleClear}
|
2026-05-20 02:02:42 +05:30
|
|
|
disabled={saving || !memory}
|
2026-04-10 12:52:27 +05:30
|
|
|
>
|
|
|
|
|
<span className="hidden sm:inline">Reset Memory</span>
|
|
|
|
|
<span className="sm:hidden">Reset</span>
|
|
|
|
|
</Button>
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button type="button" variant="secondary" size="sm" disabled={!memory}>
|
|
|
|
|
Export
|
|
|
|
|
<ChevronDown className="h-3 w-3 opacity-60" />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
|
<DropdownMenuItem onClick={handleCopyMarkdown}>
|
|
|
|
|
<ClipboardCopy className="h-4 w-4 mr-2" />
|
|
|
|
|
Copy as Markdown
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem onClick={handleDownload}>
|
|
|
|
|
<Download className="h-4 w-4 mr-2" />
|
|
|
|
|
Download as Markdown
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
</div>
|
2026-04-09 00:03:41 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|