mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: integrate Pi backend and Pi Web
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
||||
import { resolveSessionPath, buildSessionContext } from "@/lib/session-reader";
|
||||
|
||||
export async function GET(
|
||||
req: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
const url = new URL(req.url);
|
||||
const leafId = url.searchParams.get("leafId") ?? undefined;
|
||||
const deferThinking = url.searchParams.has("deferThinking");
|
||||
const deferToolResultImages = url.searchParams.has("deferMedia");
|
||||
|
||||
try {
|
||||
const filePath = await resolveSessionPath(id);
|
||||
if (!filePath) {
|
||||
return NextResponse.json({ error: "Session not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const sm = SessionManager.open(filePath);
|
||||
const context = buildSessionContext(sm.getEntries() as never, leafId, {
|
||||
deferThinking,
|
||||
deferToolResultImages,
|
||||
});
|
||||
|
||||
return NextResponse.json({ context });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: String(error) }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user