mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
I mean, it's at a good place rn...
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import { Channel } from "@/types";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Hash, Lock } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface ChannelItemProps {
|
||||
channel: Channel;
|
||||
isSelected: boolean;
|
||||
onClick: () => void;
|
||||
unreadCount?: number;
|
||||
}
|
||||
|
||||
export function ChannelItem({
|
||||
channel,
|
||||
isSelected,
|
||||
onClick,
|
||||
unreadCount = 0,
|
||||
}: ChannelItemProps) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={cn(
|
||||
"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left transition-colors",
|
||||
isSelected
|
||||
? "bg-primary/10 text-primary"
|
||||
: "text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
{channel.is_private ? (
|
||||
<Lock className="h-4 w-4 shrink-0" />
|
||||
) : (
|
||||
<Hash className="h-4 w-4 shrink-0" />
|
||||
)}
|
||||
<span className="flex-1 truncate text-sm">{channel.name}</span>
|
||||
{unreadCount > 0 && (
|
||||
<Badge variant="destructive" className="h-5 px-1.5 text-xs">
|
||||
{unreadCount}
|
||||
</Badge>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
"use client";
|
||||
|
||||
import { Channel } from "@/types";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { ChannelItem } from "./channel-item";
|
||||
|
||||
interface ChannelSidebarProps {
|
||||
channels: Channel[] | undefined;
|
||||
isLoading: boolean;
|
||||
selectedChannelId: string | null;
|
||||
onSelectChannel: (channelId: string) => void;
|
||||
}
|
||||
|
||||
// Group channels by type
|
||||
function groupChannels(channels: Channel[]): Record<string, Channel[]> {
|
||||
const groups: Record<string, Channel[]> = {
|
||||
"Cell Channels": [],
|
||||
"Cross-Cell": [],
|
||||
Management: [],
|
||||
Special: [],
|
||||
};
|
||||
|
||||
channels.forEach((channel) => {
|
||||
if (channel.name.includes("-cell")) {
|
||||
groups["Cell Channels"].push(channel);
|
||||
} else if (channel.name.includes("-all")) {
|
||||
groups["Cross-Cell"].push(channel);
|
||||
} else if (
|
||||
channel.name.includes("pm") ||
|
||||
channel.name.includes("board")
|
||||
) {
|
||||
groups["Management"].push(channel);
|
||||
} else {
|
||||
groups["Special"].push(channel);
|
||||
}
|
||||
});
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
export function ChannelSidebar({
|
||||
channels,
|
||||
isLoading,
|
||||
selectedChannelId,
|
||||
onSelectChannel,
|
||||
}: ChannelSidebarProps) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-2 p-2">
|
||||
{[...Array(8)].map((_, i) => (
|
||||
<Skeleton key={i} className="h-8" />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!channels || channels.length === 0) {
|
||||
return (
|
||||
<div className="p-4 text-center text-muted-foreground text-sm">
|
||||
No channels available
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const grouped = groupChannels(channels);
|
||||
|
||||
return (
|
||||
<ScrollArea className="h-[calc(100vh-200px)]">
|
||||
<div className="p-2 space-y-4">
|
||||
{Object.entries(grouped).map(([group, groupChannels]) => {
|
||||
if (groupChannels.length === 0) return null;
|
||||
return (
|
||||
<div key={group}>
|
||||
<h3 className="text-xs font-medium text-muted-foreground uppercase tracking-wider px-2 mb-2">
|
||||
{group}
|
||||
</h3>
|
||||
<div className="space-y-0.5">
|
||||
{groupChannels.map((channel) => (
|
||||
<ChannelItem
|
||||
key={channel.id}
|
||||
channel={channel}
|
||||
isSelected={selectedChannelId === channel.id}
|
||||
onClick={() => onSelectChannel(channel.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useChannels } from "@/hooks/use-channels";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ChannelSidebar } from "./channel-sidebar";
|
||||
import { RefreshCw, Hash, Users, ExternalLink } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
|
||||
export function CommunicationsView() {
|
||||
const [selectedChannelId, setSelectedChannelId] = useState<string | null>(null);
|
||||
const { data: channels, isLoading: loadingChannels, refetch } = useChannels();
|
||||
|
||||
// Get selected channel
|
||||
const selectedChannel = channels?.find((c) => c.id === selectedChannelId);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Communications</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Browse channels and view messages
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Link href="/communications">
|
||||
<Button variant="outline">
|
||||
<ExternalLink className="h-4 w-4 mr-2" />
|
||||
Full View
|
||||
</Button>
|
||||
</Link>
|
||||
<Button variant="outline" onClick={() => refetch()}>
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main Content */}
|
||||
<div className="grid grid-cols-12 gap-6 h-[calc(100vh-220px)]">
|
||||
{/* Channel Sidebar */}
|
||||
<div className="col-span-12 lg:col-span-3">
|
||||
<Card className="h-full">
|
||||
<CardHeader className="py-3">
|
||||
<CardTitle className="text-sm font-medium">Channels</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0">
|
||||
<ChannelSidebar
|
||||
channels={channels}
|
||||
isLoading={loadingChannels}
|
||||
selectedChannelId={selectedChannelId}
|
||||
onSelectChannel={setSelectedChannelId}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Channel Info Area */}
|
||||
<div className="col-span-12 lg:col-span-9">
|
||||
<Card className="h-full flex flex-col">
|
||||
{selectedChannel ? (
|
||||
<>
|
||||
{/* Channel Header */}
|
||||
<CardHeader className="py-3 border-b shrink-0">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Hash className="h-5 w-5 text-muted-foreground" />
|
||||
<CardTitle className="text-lg">{selectedChannel.name}</CardTitle>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
<Users className="h-3 w-3 mr-1" />
|
||||
{selectedChannel.member_count}
|
||||
</Badge>
|
||||
</div>
|
||||
<Link href={`/communications?channel=${selectedChannel.id}`}>
|
||||
<Button variant="outline" size="sm">
|
||||
<ExternalLink className="h-4 w-4 mr-2" />
|
||||
Open Channel
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
{selectedChannel.description && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{selectedChannel.description}
|
||||
</p>
|
||||
)}
|
||||
</CardHeader>
|
||||
|
||||
{/* Channel Stats */}
|
||||
<CardContent className="flex-1 flex items-center justify-center">
|
||||
<div className="text-center space-y-4">
|
||||
<div className="grid grid-cols-2 gap-8">
|
||||
<div>
|
||||
<p className="text-3xl font-bold">{selectedChannel.message_count}</p>
|
||||
<p className="text-sm text-muted-foreground">Messages</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-3xl font-bold">{selectedChannel.group_count}</p>
|
||||
<p className="text-sm text-muted-foreground">Groups</p>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Open the channel to view sessions and send messages
|
||||
</p>
|
||||
<Link href={`/communications?channel=${selectedChannel.id}`}>
|
||||
<Button>
|
||||
View Sessions
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</CardContent>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex-1 flex items-center justify-center text-muted-foreground">
|
||||
<div className="text-center">
|
||||
<Hash className="h-12 w-12 mx-auto mb-4 opacity-50" />
|
||||
<p className="text-lg font-medium">Select a Channel</p>
|
||||
<p className="text-sm">Choose a channel from the sidebar to view details</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export { CommunicationsView } from "./communications-view";
|
||||
export { ChannelSidebar } from "./channel-sidebar";
|
||||
export { ChannelItem } from "./channel-item";
|
||||
export { MessageList } from "./message-list";
|
||||
export { MessageItem } from "./message-item";
|
||||
export { MessageComposer } from "./message-composer";
|
||||
export { MessageTypeBadge } from "./message-type-badge";
|
||||
@@ -0,0 +1,95 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Send } from "lucide-react";
|
||||
|
||||
interface MessageComposerProps {
|
||||
channelId: string;
|
||||
onSend: (message: { content: string; type: string }) => void;
|
||||
isSending?: boolean;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
const MESSAGE_TYPES = [
|
||||
{ value: "dialogue", label: "Dialogue" },
|
||||
{ value: "reasoning", label: "Reasoning" },
|
||||
{ value: "decision", label: "Decision" },
|
||||
{ value: "action", label: "Action" },
|
||||
{ value: "blocker", label: "Blocker" },
|
||||
{ value: "technical", label: "Technical" },
|
||||
];
|
||||
|
||||
export function MessageComposer({
|
||||
onSend,
|
||||
isSending,
|
||||
disabled,
|
||||
}: MessageComposerProps) {
|
||||
const [content, setContent] = useState("");
|
||||
const [type, setType] = useState("dialogue");
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!content.trim()) return;
|
||||
|
||||
onSend({ content: content.trim(), type });
|
||||
setContent("");
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSubmit(e);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="border-t p-4">
|
||||
<div className="flex items-end gap-2">
|
||||
<div className="flex-1">
|
||||
<Textarea
|
||||
value={content}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Type a message... (Shift+Enter for new line)"
|
||||
className="min-h-[60px] resize-none"
|
||||
disabled={disabled || isSending}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Select value={type} onValueChange={setType}>
|
||||
<SelectTrigger className="w-auto min-w-24 h-8">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{MESSAGE_TYPES.map((t) => (
|
||||
<SelectItem key={t.value} value={t.value}>
|
||||
{t.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
disabled={!content.trim() || disabled || isSending}
|
||||
>
|
||||
<Send className="h-4 w-4 mr-1" />
|
||||
Send
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground mt-2">
|
||||
Markdown supported. Use @agent to mention.
|
||||
</p>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import { Message } from "@/types";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Markdown } from "@/components/ui/markdown";
|
||||
import { MessageTypeBadge } from "./message-type-badge";
|
||||
import { Clock, Link2 } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { getAgentDisplayName, getAgentInitials } from "@/lib/agent-utils";
|
||||
|
||||
interface MessageItemProps {
|
||||
message: Message;
|
||||
}
|
||||
|
||||
function formatTime(timestamp: string): string {
|
||||
const date = new Date(timestamp);
|
||||
return date.toLocaleTimeString("en-US", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
}
|
||||
|
||||
export function MessageItem({ message }: MessageItemProps) {
|
||||
return (
|
||||
<div className="flex gap-3 py-3 hover:bg-muted/30 px-2 rounded-lg">
|
||||
<Avatar className="h-8 w-8 shrink-0">
|
||||
<AvatarFallback className="bg-primary/10 text-primary text-xs">
|
||||
{getAgentInitials(message.agent_id)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="font-medium text-sm">{getAgentDisplayName(message.agent_id)}</span>
|
||||
<span className="text-xs text-muted-foreground flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{formatTime(message.timestamp)}
|
||||
</span>
|
||||
<MessageTypeBadge type={message.type} />
|
||||
</div>
|
||||
<div className="text-sm mt-1">
|
||||
<Markdown>{message.content}</Markdown>
|
||||
</div>
|
||||
{/* Mentions */}
|
||||
{message.mentions.length > 0 && (
|
||||
<div className="flex items-center gap-1 mt-2">
|
||||
{message.mentions.map((mention) => (
|
||||
<Badge key={mention} variant="outline" className="text-xs">
|
||||
@{mention.slice(0, 8)}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{/* Related Task */}
|
||||
{message.task_id && (
|
||||
<Link href={"/tasks/" + message.task_id}>
|
||||
<Badge variant="outline" className="text-xs mt-2 hover:bg-muted">
|
||||
<Link2 className="h-3 w-3 mr-1" />
|
||||
Task #{message.task_id.slice(0, 8)}
|
||||
</Badge>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import { Message } from "@/types";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { MessageItem } from "./message-item";
|
||||
import { MessageSquare } from "lucide-react";
|
||||
|
||||
interface MessageListProps {
|
||||
messages: Message[] | undefined;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export function MessageList({ messages, isLoading }: MessageListProps) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4 p-4">
|
||||
{[...Array(5)].map((_, i) => (
|
||||
<div key={i} className="flex gap-3">
|
||||
<Skeleton className="h-8 w-8 rounded-full" />
|
||||
<div className="flex-1 space-y-2">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<Skeleton className="h-16 w-full" />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!messages || messages.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full text-muted-foreground">
|
||||
<MessageSquare className="h-12 w-12 mb-4 opacity-50" />
|
||||
<p>No messages yet</p>
|
||||
<p className="text-sm">Start the conversation</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollArea className="flex-1 p-4">
|
||||
<div className="space-y-1">
|
||||
{messages.map((message) => (
|
||||
<MessageItem key={message.id} message={message} />
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
"use client";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
interface MessageTypeBadgeProps {
|
||||
type: string;
|
||||
}
|
||||
|
||||
const typeConfig: Record<string, { label: string; color: string }> = {
|
||||
reasoning: { label: "reasoning", color: "bg-blue-100 text-blue-700" },
|
||||
dialogue: { label: "dialogue", color: "bg-green-100 text-green-700" },
|
||||
decision: { label: "decision", color: "bg-purple-100 text-purple-700" },
|
||||
action: { label: "action", color: "bg-orange-100 text-orange-700" },
|
||||
blocker: { label: "blocker", color: "bg-red-100 text-red-700" },
|
||||
technical: { label: "technical", color: "bg-gray-100 text-gray-700" },
|
||||
general: { label: "general", color: "bg-gray-100 text-gray-700" },
|
||||
};
|
||||
|
||||
export function MessageTypeBadge({ type }: MessageTypeBadgeProps) {
|
||||
const config = typeConfig[type] ?? typeConfig.general;
|
||||
return <Badge className={config.color + " text-xs"}>{config.label}</Badge>;
|
||||
}
|
||||
Reference in New Issue
Block a user