mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 11:09:34 +00:00
24 lines
741 B
TypeScript
24 lines
741 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getRpcSession } from "@/lib/rpc-manager";
|
|
import { resolveSessionPath } from "@/lib/session-reader";
|
|
|
|
export async function GET(
|
|
_req: Request,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
) {
|
|
const { id } = await params;
|
|
try {
|
|
if (!await resolveSessionPath(id)) {
|
|
return NextResponse.json({ error: "Session not found" }, { status: 404 });
|
|
}
|
|
|
|
const rpc = getRpcSession(id);
|
|
if (!rpc?.isAlive()) return NextResponse.json({ running: false });
|
|
|
|
const state = await rpc.send({ type: "get_state" });
|
|
return NextResponse.json({ running: true, state });
|
|
} catch (error) {
|
|
return NextResponse.json({ error: String(error) }, { status: 500 });
|
|
}
|
|
}
|