rowboat/apps/rowboatx/app/api/cli/[...path]/route.ts
tusharmagar 023a65de45 Add agent selection and artifact management to RowboatX UI
- Implemented agent selection dropdown in the input area.
- Enhanced artifact management with loading, saving, and error handling.
- Added new API routes for fetching agent summaries and run details.
- Updated sidebar to display agents, configurations, and runs dynamically.
- Introduced theme selection options in the user navigation menu.
2026-01-16 12:05:33 +05:30

71 lines
1.8 KiB
TypeScript

import { NextRequest } from "next/server";
const BACKEND = process.env.CLI_BACKEND_URL || "http://localhost:3000";
const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
};
async function forward(req: NextRequest, method: string, segments?: string[]) {
const search = req.nextUrl.search || "";
const targetPath = (segments || []).join("/");
const target = `${BACKEND}/${targetPath}${search}`;
const init: RequestInit = {
method,
headers: {
"Content-Type": req.headers.get("content-type") || "application/json",
},
};
if (method !== "GET" && method !== "HEAD") {
init.body = await req.text();
}
const res = await fetch(target, init);
const body = await res.text();
return new Response(body, {
status: res.status,
headers: {
"content-type": res.headers.get("content-type") || "application/json",
...CORS_HEADERS,
},
});
}
export async function GET(
req: NextRequest,
context: { params: Promise<{ path?: string[] }> }
) {
const { path } = await context.params;
return forward(req, "GET", path);
}
export async function POST(
req: NextRequest,
context: { params: Promise<{ path?: string[] }> }
) {
const { path } = await context.params;
return forward(req, "POST", path);
}
export async function PUT(
req: NextRequest,
context: { params: Promise<{ path?: string[] }> }
) {
const { path } = await context.params;
return forward(req, "PUT", path);
}
export async function DELETE(
req: NextRequest,
context: { params: Promise<{ path?: string[] }> }
) {
const { path } = await context.params;
return forward(req, "DELETE", path);
}
export async function OPTIONS() {
return new Response(null, { status: 204, headers: CORS_HEADERS });
}