import { CodeShowcase, CodePanel } from "@/components/react/code-showcase" import { MessageSquare, Layers, Code, Bot, Server, BookOpen, Play, Book } from "lucide-react"
<CodeShowcase tabs={[
{ label: "Chat", icon: , filename: "app.tsx" },
{ label: "Headless UI", icon: , filename: "chat.tsx" },
{ label: "Generative UI", icon: , filename: "weather-card.tsx" },
{ label: "Runtime", icon: , filename: "route.ts" },
]}>
```tsx title="app.tsx"
import { CopilotKit } from "@copilotkit/react-core";
import { CopilotSidebar } from "@copilotkit/react-core/v2";
import "@copilotkit/react-ui/v2/styles.css";
export default function App() {
return (
<CopilotKit runtimeUrl="/api/copilotkit">
<YourApp />
<CopilotSidebar/>
</CopilotKit>
);
}
```
```tsx title="chat.tsx"
import { useAgent } from "@copilotkit/react-core/v2";
export default function Chat() {
const { run, messages, isRunning } = useAgent();
return (
<div>
{messages.map((m) => (
<p key={m.id}>{m.content}</p>
))}
<button onClick={() => run("Hello!")}>
{isRunning ? "Thinking..." : "Send"}
</button>
</div>
);
}
```
```tsx title="weather-card.tsx"
import { z } from "zod";
import { useComponent } from "@copilotkit/react-core/v2";
useComponent({
name: "showWeather",
description: "Display a weather card.",
parameters: z.object({
city: z.string(),
temp: z.number(),
}),
render: ({ city, temp }) => (
<div className="rounded border p-3">
<div className="font-medium">{city}</div>
<div className="text-2xl">{temp}°F</div>
</div>
),
});
```
```ts title="api/copilotkit/route.ts" linenumbers
import { NextRequest } from "next/server";
import { HttpAgent } from "@ag-ui/client";
import { CopilotRuntime, copilotRuntimeNextJSAppRouterEndpoint } from "@copilotkit/runtime";
const runtime = new CopilotRuntime({
agents: {
default: new HttpAgent({ url: "https://your-agent.example.com" }),
},
});
export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
endpoint: "/api/copilotkit",
});
return handleRequest(req);
};
```