[taskboard] migrate fleet console to nextjs
This commit is contained in:
29
app/api/agents/[slug]/assign/route.ts
Normal file
29
app/api/agents/[slug]/assign/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { listFleetAgents } from "@/lib/agents";
|
||||
import { findTask, updateTask } from "@/lib/tasks";
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ slug: string }> },
|
||||
) {
|
||||
const { slug } = await params;
|
||||
const payload = (await request.json()) as { taskId?: number };
|
||||
if (!payload.taskId) {
|
||||
return NextResponse.json({ error: "taskId_is_required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const agents = await listFleetAgents();
|
||||
const agent = agents.find((entry) => entry.slug === slug);
|
||||
if (!agent) {
|
||||
return NextResponse.json({ error: "agent_not_found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const existing = await findTask(payload.taskId);
|
||||
if (!existing) {
|
||||
return NextResponse.json({ error: "task_not_found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const updated = await updateTask(existing.id, { assignee: agent.assignmentKey });
|
||||
return NextResponse.json({ success: true, task: updated });
|
||||
}
|
||||
7
app/api/agents/route.ts
Normal file
7
app/api/agents/route.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { listFleetAgents } from "@/lib/agents";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await listFleetAgents());
|
||||
}
|
||||
7
app/api/architecture/route.ts
Normal file
7
app/api/architecture/route.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { listArchitecture } from "@/lib/agents";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await listArchitecture());
|
||||
}
|
||||
35
app/api/tasks/[id]/route.ts
Normal file
35
app/api/tasks/[id]/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { updateTask, validateTaskPayload } from "@/lib/tasks";
|
||||
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const numericId = Number(id);
|
||||
if (!Number.isInteger(numericId) || numericId <= 0) {
|
||||
return NextResponse.json({ error: "invalid_task_id" }, { status: 400 });
|
||||
}
|
||||
|
||||
const payload = (await request.json()) as Record<string, unknown>;
|
||||
const errors = validateTaskPayload(payload as never, true);
|
||||
if (errors.length > 0) {
|
||||
return NextResponse.json({ error: "validation_error", details: errors }, { status: 400 });
|
||||
}
|
||||
|
||||
const task = await updateTask(numericId, {
|
||||
title: typeof payload.title === "string" ? payload.title : undefined,
|
||||
description: typeof payload.description === "string" ? payload.description : undefined,
|
||||
assignee: typeof payload.assignee === "string" ? payload.assignee : undefined,
|
||||
priority: payload.priority as never,
|
||||
status: payload.status as never,
|
||||
tags: Array.isArray(payload.tags) ? payload.tags.filter((tag) => typeof tag === "string") : undefined,
|
||||
});
|
||||
|
||||
if (!task) {
|
||||
return NextResponse.json({ error: "task_not_found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(task);
|
||||
}
|
||||
26
app/api/tasks/route.ts
Normal file
26
app/api/tasks/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { createTask, listTasks, validateTaskPayload } from "@/lib/tasks";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await listTasks());
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const payload = (await request.json()) as Record<string, unknown>;
|
||||
const errors = validateTaskPayload(payload as never, false);
|
||||
if (errors.length > 0) {
|
||||
return NextResponse.json({ error: "validation_error", details: errors }, { status: 400 });
|
||||
}
|
||||
|
||||
const task = await createTask({
|
||||
title: String(payload.title),
|
||||
description: typeof payload.description === "string" ? payload.description : "",
|
||||
assignee: typeof payload.assignee === "string" ? payload.assignee : "",
|
||||
priority: payload.priority as never,
|
||||
status: (payload.status as never) || "Backlog",
|
||||
tags: Array.isArray(payload.tags) ? payload.tags.filter((tag) => typeof tag === "string") : [],
|
||||
});
|
||||
|
||||
return NextResponse.json(task, { status: 201 });
|
||||
}
|
||||
37
app/api/usage/stats/route.ts
Normal file
37
app/api/usage/stats/route.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { all } from "@/lib/db";
|
||||
|
||||
type UsageRow = {
|
||||
agent: string;
|
||||
provider: string;
|
||||
model: string;
|
||||
tokens_used: number;
|
||||
cost_estimate: number;
|
||||
};
|
||||
|
||||
export async function GET() {
|
||||
const rows = await all<UsageRow>("SELECT * FROM usage_tracking ORDER BY timestamp DESC");
|
||||
const result = rows.reduce(
|
||||
(accumulator, row) => {
|
||||
accumulator.totalRequests += 1;
|
||||
accumulator.totalTokens += row.tokens_used || 0;
|
||||
accumulator.totalCost += row.cost_estimate || 0;
|
||||
if (!accumulator.byAgent[row.agent]) {
|
||||
accumulator.byAgent[row.agent] = { requests: 0, tokens: 0, cost: 0 };
|
||||
}
|
||||
accumulator.byAgent[row.agent].requests += 1;
|
||||
accumulator.byAgent[row.agent].tokens += row.tokens_used || 0;
|
||||
accumulator.byAgent[row.agent].cost += row.cost_estimate || 0;
|
||||
return accumulator;
|
||||
},
|
||||
{
|
||||
totalRequests: 0,
|
||||
totalTokens: 0,
|
||||
totalCost: 0,
|
||||
byAgent: {} as Record<string, { requests: number; tokens: number; cost: number }>,
|
||||
},
|
||||
);
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
38
app/api/wiki/[filename]/route.ts
Normal file
38
app/api/wiki/[filename]/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { deleteWikiPage, readWikiPage, updateWikiPage } from "@/lib/wiki";
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ filename: string }> },
|
||||
) {
|
||||
const { filename } = await params;
|
||||
const page = readWikiPage(filename);
|
||||
if (!page) {
|
||||
return NextResponse.json({ error: "wiki_page_not_found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json(page);
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ filename: string }> },
|
||||
) {
|
||||
const { filename } = await params;
|
||||
const payload = (await request.json()) as { content?: string };
|
||||
if (typeof payload.content !== "string") {
|
||||
return NextResponse.json({ error: "content_is_required" }, { status: 400 });
|
||||
}
|
||||
|
||||
updateWikiPage(filename, payload.content);
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ filename: string }> },
|
||||
) {
|
||||
const { filename } = await params;
|
||||
deleteWikiPage(filename);
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
17
app/api/wiki/route.ts
Normal file
17
app/api/wiki/route.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { createWikiPage, listWikiPages } from "@/lib/wiki";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(listWikiPages());
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const payload = (await request.json()) as { title?: string };
|
||||
if (!payload.title) {
|
||||
return NextResponse.json({ error: "title_is_required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const filename = createWikiPage(payload.title);
|
||||
return NextResponse.json({ filename, success: true }, { status: 201 });
|
||||
}
|
||||
Reference in New Issue
Block a user