← back to Ventura Claw
app/app/api/chat/route.ts
43 lines
import { NextResponse } from "next/server";
import { ALL_CONNECTORS } from "@/lib/mcp/all-connectors";
interface ToolCall { connector: string; action: string; queued: boolean; }
function plan(message: string): { reply: string; toolCalls: ToolCall[] } {
const m = message.toLowerCase();
const calls: ToolCall[] = [];
const matchAction = (id: string) => {
for (const c of ALL_CONNECTORS) {
const a = c.actions.find(x => x.id === id);
if (a) return { connector: c.meta.id, action: a.id, queued: a.sensitive };
}
return null;
};
if (/(all|every).*(social|channel|platform)/.test(m) || /post.*(everywhere|all)/.test(m)) {
["instagram.media.publish","facebook.post.create","tiktok.video.publish","pinterest.pin.create","linkedin.post.create","youtube_shorts.short.upload","x_twitter.post.create","threads.post.create","bluesky.post.create","reddit.submission.create"]
.forEach(id => { const c = matchAction(id); if (c) calls.push(c); });
return { reply: `Drafting posts for all 10 social platforms. ${calls.length} actions queued for your approval.`, toolCalls: calls };
}
if (/refund/.test(m)) {
const c = matchAction("stripe.refund.create"); if (c) calls.push(c);
return { reply: "Refund queued for approval.", toolCalls: calls };
}
if (/email|campaign/.test(m) && /mailchimp|send/.test(m)) {
const c = matchAction("mailchimp.campaign.send"); if (c) calls.push(c);
return { reply: "Mailchimp campaign drafted and queued.", toolCalls: calls };
}
if (/order/.test(m) && /shopify/.test(m)) {
return { reply: "I can pull recent Shopify orders, fulfill, refund, or update tags. What do you want to do?", toolCalls: [] };
}
return {
reply: `I'm connected to ${ALL_CONNECTORS.length} tools. Try: "post our newest product to all socials", "refund order #1234 in Stripe", "draft a Mailchimp campaign for new arrivals", or "create a ClickUp task for the design team".`,
toolCalls: []
};
}
export async function POST(req: Request) {
const { message } = await req.json();
if (!message) return NextResponse.json({ error: "missing message" }, { status: 400 });
return NextResponse.json(plan(message));
}