"use client"; import { ProverbsCard } from "@/components/proverbs"; import { WeatherCard } from "@/components/weather"; import { MoonCard } from "@/components/moon"; import { AgentState } from "@/lib/types"; import { useCoAgent, useCopilotAction } from "@copilotkit/react-core"; import { CopilotKitCSSProperties, CopilotSidebar } from "@copilotkit/react-ui"; import { useState } from "react"; export default function CopilotKitPage() { const [themeColor, setThemeColor] = useState("#6366f1"); // 🪁 Frontend Actions: https://docs.copilotkit.ai/microsoft-agent-framework/frontend-actions useCopilotAction({ name: "setThemeColor", parameters: [ { name: "themeColor", description: "The theme color to set. Make sure to pick nice colors.", required: true, }, ], handler({ themeColor }) { setThemeColor(themeColor); }, }); return (
); } function YourMainContent({ themeColor }: { themeColor: string }) { // 🪁 Shared State: https://docs.copilotkit.ai/microsoft-agent-framework/shared-state const { state, setState } = useCoAgent({ name: "my_agent", initialState: { proverbs: [ "CopilotKit may be new, but its the best thing since sliced bread.", ], }, }); //🪁 Generative UI: https://docs.copilotkit.ai/microsoft-agent-framework/generative-ui useCopilotAction( { name: "get_weather", description: "Get the weather for a given location.", available: "disabled", parameters: [{ name: "location", type: "string", required: true }], render: ({ args }) => { return ; }, }, [themeColor], ); // 🪁 Human In the Loop: https://docs.copilotkit.ai/microsoft-agent-framework/human-in-the-loop useCopilotAction( { name: "go_to_moon", description: "Go to the moon on request. This action requires human approval and will render the MoonCard UI for confirmation.", available: "disabled", renderAndWaitForResponse: ({ respond, status }) => { return ( ); }, }, [themeColor], ); return (
); }