@agentdao/next
v0.1.7
Published
Next.js integration for AgentDAO
Downloads
70
Maintainers
Readme
@agentdao/next
Next.js integration for AgentDAO.
Installation
npm install @agentdao/next
# or
yarn add @agentdao/next
# or
pnpm add @agentdao/nextUsage
API Routes
Create an API route for your agent:
// pages/api/agent.ts
import { createAgent } from '@developersagentdao/next';
export default createAgent({
name: 'my-agent',
handler: async (req, res) => {
// Your agent logic here
return { message: 'Hello from my agent!' };
}
});Client-side
Use agents in your client components:
// app/page.tsx
import { getAgent } from '@developersagentdao/next';
// Fetch an agent
const agent = await getAgent('my-agent-id');API Reference
createAgent
Creates a Next.js API route handler for an agent.
createAgent(config: AgentConfig): NextApiHandlerConfig Options
name(string): The name of the agenthandler(function): The function that processes requests and returns responses
getAgent
Fetches agent data on the server.
getAgent(agentId: string): Promise<Agent>Error Handling
The API routes automatically handle errors and return appropriate status codes:
export default createAgent({
name: 'my-agent',
handler: async (req, res) => {
try {
const result = await processRequest(req);
return result;
} catch (error) {
res.status(500).json({ error: error.message });
}
}
});License
MIT
API Key Requirement
All API usage requires your AgentDAO API key. Pass it to the AgentBridgeClient and use it with your Next.js integrations.
Example Usage
import { AgentBridgeClient } from '@agentdao/core';
const client = new AgentBridgeClient(
process.env.NEXT_PUBLIC_API_URL!,
process.env.AGENTDAO_API_KEY // Your AgentDAO API key
);- Set
NEXT_PUBLIC_API_URLandAGENTDAO_API_KEYin your environment variables or.envfile.
