Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions apps/web/src/app/api/agents/[agentId]/connections/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { NextRequest, NextResponse } from "next/server";
import { resolveApiAuth } from "@/lib/api-auth";
import { handleServiceError, unauthorized } from "@/lib/api-utils";
import { invalidateGatewayCache } from "@/lib/gateway-invalidate";
import {
getAgentAppConnections,
updateAgentAppConnections,
} from "@/lib/services/agent-service";
import { updateAgentAppConnectionsSchema } from "@/lib/validations/agent";

type Params = { params: Promise<{ agentId: string }> };

export const GET = async (request: NextRequest, { params }: Params) => {
try {
const auth = await resolveApiAuth(request);
if (!auth) return unauthorized();

const { agentId } = await params;
const appConnectionIds = await getAgentAppConnections(
auth.accountId,
agentId,
);
return NextResponse.json(appConnectionIds);
} catch (err) {
return handleServiceError(err);
}
};

export const PUT = async (request: NextRequest, { params }: Params) => {
try {
const auth = await resolveApiAuth(request);
if (!auth) return unauthorized();

const { agentId } = await params;
const body = await request.json().catch(() => null);
const parsed = updateAgentAppConnectionsSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid request body" },
{ status: 400 },
);
}

await updateAgentAppConnections(
auth.accountId,
agentId,
parsed.data.appConnectionIds,
);
invalidateGatewayCache(request);
return NextResponse.json({ success: true });
} catch (err) {
return handleServiceError(err);
}
};
4 changes: 4 additions & 0 deletions apps/web/src/lib/validations/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ export const secretModeSchema = z.object({
export const updateAgentSecretsSchema = z.object({
secretIds: z.array(z.string()),
});

export const updateAgentAppConnectionsSchema = z.object({
appConnectionIds: z.array(z.string()),
});
Loading