mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
453097ff18
Flatten langgraph-python, langgraph-js, and mcp-apps starters so npm install && npm run dev works out of the box. Replace Turborepo with concurrently, move apps/* to root, update Dockerfiles, READMEs, and entrypoints. Also remove stray pnpm-lock.yaml from a2a-a2ui and ms-agent-framework-dotnet starters.
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import {
|
|
CopilotRuntime,
|
|
ExperimentalEmptyAdapter,
|
|
copilotRuntimeNextJSAppRouterEndpoint,
|
|
} from "@copilotkit/runtime";
|
|
import { BuiltInAgent } from "@copilotkit/runtime/v2";
|
|
import { NextRequest } from "next/server";
|
|
import { MCPAppsMiddleware } from "@ag-ui/mcp-apps-middleware";
|
|
|
|
// 1. Define the agent middleware
|
|
const middlewares = [
|
|
// 1.1. MCP Apps Middleware
|
|
new MCPAppsMiddleware({
|
|
mcpServers: [
|
|
{
|
|
type: "http",
|
|
url: "http://localhost:3108/mcp",
|
|
serverId: "threejs", // Recommended: stable identifier
|
|
},
|
|
],
|
|
}),
|
|
// 1.2. More middlewares can be added here
|
|
];
|
|
|
|
// 2. Create the agent
|
|
const agent = new BuiltInAgent({
|
|
model: "openai/gpt-4o",
|
|
prompt: "You are a helpful assistant.",
|
|
});
|
|
|
|
// 3. Apply the middleware to the agent
|
|
for (const middleware of middlewares) {
|
|
agent.use(middleware);
|
|
}
|
|
|
|
// 4. Create the service adapter, empty if not relevant
|
|
const serviceAdapter = new ExperimentalEmptyAdapter();
|
|
|
|
// 5. Create the runtime
|
|
const runtime = new CopilotRuntime({
|
|
agents: {
|
|
default: agent,
|
|
},
|
|
});
|
|
|
|
// 6. Create the API route
|
|
export const POST = async (req: NextRequest) => {
|
|
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
|
|
runtime,
|
|
serviceAdapter,
|
|
endpoint: "/api/copilotkit",
|
|
});
|
|
|
|
return handleRequest(req);
|
|
};
|