Files
zk-data-agent/frontend/app/app/api/claw/context-budget/route.ts
T
2026-05-06 17:19:13 +08:00

38 lines
1.1 KiB
TypeScript

import { getCurrentAccount } from "@/lib/claw-auth";
const CLAW_API_URL = process.env.CLAW_API_URL ?? "http://127.0.0.1:8765";
export async function GET(req: Request) {
const account = await getCurrentAccount();
if (!account)
return Response.json({ error: "请先登录账号" }, { status: 401 });
const incoming = new URL(req.url);
const url = new URL(`${CLAW_API_URL}/api/context-budget`);
url.searchParams.set("account_id", account.id);
const sessionId = incoming.searchParams.get("session_id");
if (sessionId) url.searchParams.set("session_id", sessionId);
try {
const response = await fetch(url, { cache: "no-store" });
const payload = await response.text();
return new Response(payload, {
status: response.status,
headers: {
"content-type":
response.headers.get("content-type") ?? "application/json",
},
});
} catch (err) {
return Response.json(
{
error:
err instanceof Error
? `Unable to reach ZK Data Agent backend: ${err.message}`
: "Unable to reach ZK Data Agent backend",
},
{ status: 502 },
);
}
}