Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: per-agent channel persistence and HTML artifact iframe rendering

Gusdb7b0d9acace
diff --git a/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx b/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx
index d213cfcd6..ae5b932e0 100644
--- a/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx
+++ b/src/web/src/app/(app)/w/[slug]/agents/[id]/layout.tsx
@@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
import { AgentEditForm } from "@/components/agent-edit-form";
import { ChannelBar } from "@/components/channel-bar";
+import { useChannel } from "@/contexts/channel-context";
import { Skeleton } from "@/components/ui/skeleton";
import { AgentStatusBadge } from "@/components/agent-status-badge";
import { FolderOpen, GitBranch, History, Mail, MessageSquare, MoreHorizontal, Pencil, Trash2, Video, X } from "lucide-react";
@@ -53,6 +54,13 @@ export default function AgentDetailLayout({ children }: { children: ReactNode })
const [agentDeleting, setAgentDeleting] = useState(false);
const [modelOptions, setModelOptions] = useState<Record<string, string[]>>({});
+ const { setAgentId: setChannelAgentId } = useChannel();
+
+ useEffect(() => {
+ setChannelAgentId(agentId);
+ return () => setChannelAgentId(null);
+ }, [agentId, setChannelAgentId]);
+
useEffect(() => {
fetchModelOptions().then(setModelOptions).catch(() => {});
}, []);
diff --git a/src/web/src/components/agent-chat/artifact-sheet.tsx b/src/web/src/components/agent-chat/artifact-sheet.tsx
index 32343e54b..9269c00db 100644
--- a/src/web/src/components/agent-chat/artifact-sheet.tsx
+++ b/src/web/src/components/agent-chat/artifact-sheet.tsx
@@ -11,7 +11,8 @@ import {
import type { Artifact } from "@alook/shared";
import { FileText, Download, X, ArrowLeft } from "lucide-react";
import { Button } from "@/components/ui/button";
-import { ArtifactContentRenderer, getArtifactUrl } from "@/components/artifact-content-renderer";
+import { ArtifactContentRenderer, getArtifactUrl, isHtmlType } from "@/components/artifact-content-renderer";
+import { cn } from "@/lib/utils";
export function formatSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
@@ -118,7 +119,10 @@ export function ArtifactSheet({ open, onOpenChange, artifacts, workspaceId, init
</Button>
</div>
</SheetHeader>
- <SheetBody className="thin-scrollbar">
+ <SheetBody className={cn(
+ "thin-scrollbar",
+ isHtmlType(selectedArtifact.content_type) && "!p-0 !overflow-hidden"
+ )}>
<ArtifactContentRenderer artifact={selectedArtifact} workspaceId={workspaceId} />
</SheetBody>
</>
diff --git a/src/web/src/components/artifact-content-renderer.tsx b/src/web/src/components/artifact-content-renderer.tsx
index 94937ebd5..6d174be20 100644
--- a/src/web/src/components/artifact-content-renderer.tsx
+++ b/src/web/src/components/artifact-content-renderer.tsx
@@ -22,6 +22,10 @@ export function isTextType(contentType: string): boolean {
return false;
}
+export function isHtmlType(contentType: string): boolean {
+ return contentType.startsWith("text/html");
+}
+
export function isImageType(contentType: string): boolean {
return contentType.startsWith("image/");
}
@@ -52,7 +56,7 @@ export function ArtifactContentRenderer({ artifact, workspaceId }: ArtifactConte
const url = getArtifactUrl(artifact.id, workspaceId);
useEffect(() => {
- if (isTextType(artifact.content_type)) {
+ if (isTextType(artifact.content_type) && !isHtmlType(artifact.content_type)) {
setLoading(true);
setContent(null);
getArtifactContent(artifact.id, workspaceId)
@@ -82,6 +86,10 @@ export function ArtifactContentRenderer({ artifact, workspaceId }: ArtifactConte
);
}
+ if (isHtmlType(artifact.content_type)) {
+ return <HtmlArtifactFrame url={url} title={artifact.filename} />;
+ }
+
if (isTextType(artifact.content_type)) {
if (isMarkdown(artifact.filename)) {
return (
@@ -111,3 +119,15 @@ export function ArtifactContentRenderer({ artifact, workspaceId }: ArtifactConte
</div>
);
}
+
+function HtmlArtifactFrame({ url, title }: { url: string; title: string }) {
+ return (
+ <iframe
+ src={url}
+ sandbox="allow-same-origin"
+ className="w-full h-full rounded-b-xl overflow-hidden"
+ style={{ border: "none", display: "block" }}
+ title={title}
+ />
+ );
+}
diff --git a/src/web/src/contexts/channel-context.tsx b/src/web/src/contexts/channel-context.tsx
index 32c9dc909..268dd1845 100644
--- a/src/web/src/contexts/channel-context.tsx
+++ b/src/web/src/contexts/channel-context.tsx
@@ -21,6 +21,7 @@ interface ChannelContextValue {
activeChannel: string;
loading: boolean;
setActiveChannel: (name: string) => void;
+ setAgentId: (id: string | null) => void;
createChannel: (name: string) => Promise<Channel>;
renameChannel: (id: string, name: string) => Promise<void>;
deleteChannel: (id: string) => Promise<void>;
@@ -29,8 +30,10 @@ interface ChannelContextValue {
const ChannelContext = createContext<ChannelContextValue | null>(null);
-function storageKey(workspaceId: string) {
- return `alook:channel:${workspaceId}`;
+function storageKey(workspaceId: string, agentId?: string | null) {
+ return agentId
+ ? `alook:channel:${workspaceId}:${agentId}`
+ : `alook:channel:${workspaceId}`;
}
export function ChannelProvider({
@@ -43,6 +46,7 @@ export function ChannelProvider({
const [channels, setChannels] = useState<Channel[]>([]);
const [activeChannel, setActiveChannelState] = useState<string>("default");
const [loading, setLoading] = useState(true);
+ const [agentId, setAgentId] = useState<string | null>(null);
const fetchChannels = useCallback(async () => {
try {
@@ -55,24 +59,27 @@ export function ChannelProvider({
}, [workspaceId]);
useEffect(() => {
- const stored =
- typeof window !== "undefined"
- ? localStorage.getItem(storageKey(workspaceId))
- : null;
- if (stored) {
- setActiveChannelState(stored);
- }
fetchChannels().finally(() => setLoading(false));
}, [workspaceId, fetchChannels]);
+ useEffect(() => {
+ if (typeof window === "undefined") return;
+ const stored = localStorage.getItem(storageKey(workspaceId, agentId));
+ setActiveChannelState(stored ?? "default");
+ }, [workspaceId, agentId]);
+
const setActiveChannel = useCallback(
(name: string) => {
setActiveChannelState(name);
if (typeof window !== "undefined") {
- localStorage.setItem(storageKey(workspaceId), name);
+ try {
+ localStorage.setItem(storageKey(workspaceId, agentId), name);
+ } catch {
+ // localStorage quota exceeded or unavailable
+ }
}
},
- [workspaceId]
+ [workspaceId, agentId]
);
const createChannel = useCallback(
@@ -115,6 +122,7 @@ export function ChannelProvider({
activeChannel,
loading,
setActiveChannel,
+ setAgentId,
createChannel,
renameChannel,
deleteChannel,