feat(web): MS23-P2-002 OrchestratorPanel SSE stream component
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
|
||||
import { GlobalAgentRoster } from "@/components/mission-control/GlobalAgentRoster";
|
||||
import { MissionControlPanel } from "@/components/mission-control/MissionControlPanel";
|
||||
import { useSessions } from "@/hooks/useMissionControl";
|
||||
|
||||
const DEFAULT_PANEL_SLOTS = ["panel-1", "panel-2", "panel-3", "panel-4"] as const;
|
||||
|
||||
export function MissionControlLayout(): React.JSX.Element {
|
||||
const { sessions } = useSessions();
|
||||
|
||||
const panelSessionIds = [sessions[0]?.id, undefined, undefined, undefined] as const;
|
||||
|
||||
return (
|
||||
<section className="h-full min-h-0 overflow-hidden" aria-label="Mission Control">
|
||||
<div className="grid h-full min-h-0 gap-4 xl:grid-cols-[280px_minmax(0,1fr)]">
|
||||
@@ -13,7 +18,7 @@ export function MissionControlLayout(): React.JSX.Element {
|
||||
<GlobalAgentRoster />
|
||||
</aside>
|
||||
<main className="h-full min-h-0 overflow-hidden">
|
||||
<MissionControlPanel panels={DEFAULT_PANEL_SLOTS} />
|
||||
<MissionControlPanel panels={DEFAULT_PANEL_SLOTS} panelSessionIds={panelSessionIds} />
|
||||
</main>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -4,14 +4,24 @@ import { OrchestratorPanel } from "@/components/mission-control/OrchestratorPane
|
||||
|
||||
interface MissionControlPanelProps {
|
||||
panels: readonly string[];
|
||||
panelSessionIds?: readonly (string | undefined)[];
|
||||
}
|
||||
|
||||
export function MissionControlPanel({ panels }: MissionControlPanelProps): React.JSX.Element {
|
||||
export function MissionControlPanel({
|
||||
panels,
|
||||
panelSessionIds,
|
||||
}: MissionControlPanelProps): React.JSX.Element {
|
||||
return (
|
||||
<div className="grid h-full min-h-0 auto-rows-fr grid-cols-1 gap-4 overflow-y-auto pr-1 md:grid-cols-2">
|
||||
{panels.map((panelId) => (
|
||||
<OrchestratorPanel key={panelId} />
|
||||
))}
|
||||
{panels.map((panelId, index) => {
|
||||
const sessionId = panelSessionIds?.[index];
|
||||
|
||||
if (sessionId === undefined) {
|
||||
return <OrchestratorPanel key={panelId} />;
|
||||
}
|
||||
|
||||
return <OrchestratorPanel key={panelId} sessionId={sessionId} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,117 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { BadgeVariant } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import {
|
||||
useSessionStream,
|
||||
type MissionControlConnectionStatus,
|
||||
type MissionControlMessageRole,
|
||||
} from "@/hooks/useMissionControl";
|
||||
|
||||
const ROLE_BADGE_VARIANT: Record<MissionControlMessageRole, BadgeVariant> = {
|
||||
user: "badge-blue",
|
||||
assistant: "status-success",
|
||||
tool: "badge-amber",
|
||||
system: "badge-muted",
|
||||
};
|
||||
|
||||
const CONNECTION_DOT_CLASS: Record<MissionControlConnectionStatus, string> = {
|
||||
connected: "bg-emerald-500",
|
||||
connecting: "bg-amber-500",
|
||||
error: "bg-red-500",
|
||||
};
|
||||
|
||||
const CONNECTION_TEXT: Record<MissionControlConnectionStatus, string> = {
|
||||
connected: "Connected",
|
||||
connecting: "Connecting",
|
||||
error: "Error",
|
||||
};
|
||||
|
||||
export interface OrchestratorPanelProps {
|
||||
sessionId?: string;
|
||||
}
|
||||
|
||||
function formatRelativeTimestamp(timestamp: string): string {
|
||||
const parsedDate = new Date(timestamp);
|
||||
if (Number.isNaN(parsedDate.getTime())) {
|
||||
return "just now";
|
||||
}
|
||||
|
||||
return formatDistanceToNow(parsedDate, { addSuffix: true });
|
||||
}
|
||||
|
||||
export function OrchestratorPanel({ sessionId }: OrchestratorPanelProps): React.JSX.Element {
|
||||
const { messages, status, error } = useSessionStream(sessionId ?? "");
|
||||
const bottomAnchorRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
bottomAnchorRef.current?.scrollIntoView({ block: "end" });
|
||||
}, [messages.length]);
|
||||
|
||||
if (!sessionId) {
|
||||
return (
|
||||
<Card className="flex h-full min-h-[220px] flex-col">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Orchestrator Panel</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-1 items-center justify-center text-sm text-muted-foreground">
|
||||
Select an agent to view its stream
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export function OrchestratorPanel(): React.JSX.Element {
|
||||
return (
|
||||
<Card className="flex h-full min-h-[220px] flex-col">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Orchestrator Panel</CardTitle>
|
||||
<CardHeader className="space-y-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<CardTitle className="text-base">Orchestrator Panel</CardTitle>
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span
|
||||
className={`h-2.5 w-2.5 rounded-full ${CONNECTION_DOT_CLASS[status]} ${
|
||||
status === "connecting" ? "animate-pulse" : ""
|
||||
}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span>{CONNECTION_TEXT[status]}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p className="truncate text-xs text-muted-foreground">Session: {sessionId}</p>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-1 items-center justify-center text-sm text-muted-foreground">
|
||||
Select an agent
|
||||
<CardContent className="flex min-h-0 flex-1 p-0">
|
||||
<ScrollArea className="h-full w-full">
|
||||
<div className="flex min-h-full flex-col gap-3 p-4">
|
||||
{messages.length === 0 ? (
|
||||
<p className="mt-6 text-center text-sm text-muted-foreground">
|
||||
{error ?? "Waiting for messages..."}
|
||||
</p>
|
||||
) : (
|
||||
messages.map((message) => (
|
||||
<article
|
||||
key={message.id}
|
||||
className="rounded-lg border border-border/70 bg-card px-3 py-2"
|
||||
>
|
||||
<div className="mb-2 flex items-center justify-between gap-2">
|
||||
<Badge variant={ROLE_BADGE_VARIANT[message.role]} className="uppercase">
|
||||
{message.role}
|
||||
</Badge>
|
||||
<time className="text-xs text-muted-foreground">
|
||||
{formatRelativeTimestamp(message.timestamp)}
|
||||
</time>
|
||||
</div>
|
||||
<p className="whitespace-pre-wrap break-words text-sm text-foreground">
|
||||
{message.content}
|
||||
</p>
|
||||
</article>
|
||||
))
|
||||
)}
|
||||
<div ref={bottomAnchorRef} />
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
15
apps/web/src/components/ui/scroll-area.tsx
Normal file
15
apps/web/src/components/ui/scroll-area.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as React from "react";
|
||||
|
||||
export type ScrollAreaProps = React.HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
export const ScrollArea = React.forwardRef<HTMLDivElement, ScrollAreaProps>(
|
||||
({ className = "", children, ...props }, ref) => {
|
||||
return (
|
||||
<div ref={ref} className={`relative overflow-hidden ${className}`} {...props}>
|
||||
<div className="h-full w-full overflow-auto">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ScrollArea.displayName = "ScrollArea";
|
||||
Reference in New Issue
Block a user