fix: agent route to add json parser

This commit is contained in:
charles-gauthereau
2026-05-28 08:16:34 +02:00
parent c1b71e7772
commit 7a97721abf
3 changed files with 7 additions and 26 deletions
-5
View File
@@ -1,10 +1,5 @@
import {NextResponse} from "next/server";
import {withApiKey} from "@/lib/api-v1/middleware";
import {db} from "@/db";
import * as drizzleDb from "@/db";
import {eq, and, or, isNull} from "drizzle-orm";
import {withUpdatedAt} from "@/db/utils";
import {v4 as uuidv4} from "uuid";
import {logger} from "@/lib/logger";
import {ApiKeyContext} from "@/lib/api-v1/types";
import {getAgent, resolveAgentAccess} from "@/lib/api-v1/services/agents";
+7 -20
View File
@@ -2,13 +2,14 @@ import { NextResponse } from "next/server";
import { withApiKey } from "@/lib/api-v1/middleware";
import { db } from "@/db";
import * as drizzleDb from "@/db";
import { inArray, eq, count, and, or, isNull } from "drizzle-orm";
import { inArray, eq, and, or, isNull } from "drizzle-orm";
import { z } from "zod";
import { logger } from "@/lib/logger";
import {createAgentService} from "@/features/agents/agents.action";
import { ActionError } from "@/lib/safe-actions/actions";
import {getAccessibleAgentIds} from "@/lib/api-v1/services/agents";
import {ApiKeyContext} from "@/lib/api-v1/types";
import {parseJsonBody} from "@/lib/api-v1/validation/json-body";
const log = logger.child({ module: "api/v1/agents" });
@@ -45,28 +46,14 @@ const CreateAgentSchema = z.object({
export const POST = withApiKey(
async (req: Request, ctx: ApiKeyContext) => {
try {
const body = await req.json().catch(() => null);
if (!body) {
return NextResponse.json(
{ error: "Invalid JSON body" },
{ status: 422 }
);
const body = await parseJsonBody(req, CreateAgentSchema);
if (!body.ok) {
return body.response;
}
const parsed = CreateAgentSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{
error: parsed.error.issues[0]?.message ??
"Invalid payload",
},
{ status: 422 }
);
}
const { name, organizationId } = parsed.data;
const { name, organizationId } = body.data;
const org = ctx.organizations.find(
(org) => org.id === organizationId
-1
View File
@@ -2,7 +2,6 @@ import { db } from "@/db";
import * as drizzleDb from "@/db";
import { eq, inArray, and, or, isNull } from "drizzle-orm";
import {ApiKeyContextUser} from "@/lib/api-v1/types";
import {notFound} from "next/navigation";
import {AgentWith} from "@/db/schema/08_agent";
export async function getAccessibleAgentIds(