mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 00:16:29 +02:00
- 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.
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import { cliClient, RunEvent } from '@/lib/cli-client';
|
|
import { NextRequest } from 'next/server';
|
|
|
|
export const runtime = 'nodejs';
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
/**
|
|
* POST /api/chat
|
|
* Creates a new conversation or sends a message to existing one
|
|
*/
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
const { message, runId, agentId } = body;
|
|
|
|
if (!message || typeof message !== 'string') {
|
|
return Response.json(
|
|
{ error: 'Message is required' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
let currentRunId = runId;
|
|
|
|
// Create new run if no runId provided
|
|
if (!currentRunId) {
|
|
const run = await cliClient.createRun({
|
|
agentId: agentId || 'copilot',
|
|
});
|
|
currentRunId = run.id;
|
|
}
|
|
|
|
// Always send the message (this triggers the agent runtime)
|
|
await cliClient.sendMessage(currentRunId, message);
|
|
|
|
// Return the run ID
|
|
return Response.json({ runId: currentRunId });
|
|
} catch (error) {
|
|
console.error('Chat API error:', error);
|
|
return Response.json(
|
|
{ error: 'Failed to process message' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* GET /api/chat?runId=xxx
|
|
* Get a specific run's details
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const runId = searchParams.get('runId');
|
|
|
|
if (!runId) {
|
|
// List all runs
|
|
const result = await cliClient.listRuns();
|
|
return Response.json(result);
|
|
}
|
|
|
|
// Get specific run
|
|
const run = await cliClient.getRun(runId);
|
|
return Response.json(run);
|
|
} catch (error) {
|
|
console.error('Chat API error:', error);
|
|
return Response.json(
|
|
{ error: 'Failed to fetch run' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|