import { AgentsDashboard } from "@/components/agents/agents-dashboard";
import { loadAgentFeed } from "@/lib/agent-monitor";
import { AgentStatus } from "@/types/agent";

type AgentsPageProps = {
  searchParams?: Promise<{
    status?: string;
  }>;
};

function isAgentStatus(value: string | undefined): value is AgentStatus {
  return value === "working" || value === "idle" || value === "warning" || value === "offline";
}

export default async function AgentsPage({ searchParams }: AgentsPageProps) {
  const resolvedSearchParams = searchParams ? await searchParams : undefined;
  const activeStatus = isAgentStatus(resolvedSearchParams?.status) ? resolvedSearchParams.status : "all";
  const feed = await loadAgentFeed(activeStatus);

  return (
    <main className="page-shell">
      <section className="page-title">
        <h1>Agent 观察室</h1>
        <p>这里直接看 OpenClaw 各个 agent 的任务、心跳、队列、主机和最近输出，方便做真实运维观察。</p>
      </section>
      <AgentsDashboard initialFeed={feed} initialStatus={activeStatus} />
    </main>
  );
}
