diff --git a/apps/next/src/app/api/box/file/route.ts b/apps/next/src/app/api/box/file/route.ts new file mode 100644 index 0000000..7b29edf --- /dev/null +++ b/apps/next/src/app/api/box/file/route.ts @@ -0,0 +1,21 @@ +import { proxyBox, withBox } from '@/lib/agent-worker-proxy'; + +export const GET = async (request: Request) => + await withBox(async (username) => { + const url = new URL(request.url); + return await proxyBox( + username, + 'file', + { method: 'GET' }, + new URLSearchParams({ path: url.searchParams.get('path') ?? '' }), + ); + }); + +export const PUT = async (request: Request) => + await withBox( + async (username) => + await proxyBox(username, 'file', { + method: 'PUT', + body: await request.text(), + }), + ); diff --git a/apps/next/src/app/api/box/lifecycle/route.ts b/apps/next/src/app/api/box/lifecycle/route.ts new file mode 100644 index 0000000..365aab6 --- /dev/null +++ b/apps/next/src/app/api/box/lifecycle/route.ts @@ -0,0 +1,10 @@ +import { proxyBox, withBox } from '@/lib/agent-worker-proxy'; + +export const POST = async (request: Request) => + await withBox( + async (username) => + await proxyBox(username, 'lifecycle', { + method: 'POST', + body: await request.text(), + }), + ); diff --git a/apps/next/src/app/api/box/status/route.ts b/apps/next/src/app/api/box/status/route.ts new file mode 100644 index 0000000..838a103 --- /dev/null +++ b/apps/next/src/app/api/box/status/route.ts @@ -0,0 +1,6 @@ +import { proxyBox, withBox } from '@/lib/agent-worker-proxy'; + +export const GET = async () => + await withBox( + async (username) => await proxyBox(username, 'status', { method: 'GET' }), + ); diff --git a/apps/next/src/app/api/box/terminal-token/route.ts b/apps/next/src/app/api/box/terminal-token/route.ts new file mode 100644 index 0000000..855e5a7 --- /dev/null +++ b/apps/next/src/app/api/box/terminal-token/route.ts @@ -0,0 +1,14 @@ +import { NextResponse } from 'next/server'; +import { mintBoxTerminalToken, resolveBoxUsername } from '@/lib/agent-worker-proxy'; + +export const GET = async () => { + const resolved = await resolveBoxUsername(); + if (!resolved.ok) return resolved.response; + const minted = mintBoxTerminalToken(resolved.username); + return minted + ? NextResponse.json(minted) + : NextResponse.json( + { error: 'Terminal is not configured on this deployment.' }, + { status: 503 }, + ); +}; diff --git a/apps/next/src/app/api/box/tree/route.ts b/apps/next/src/app/api/box/tree/route.ts new file mode 100644 index 0000000..77a27f5 --- /dev/null +++ b/apps/next/src/app/api/box/tree/route.ts @@ -0,0 +1,6 @@ +import { proxyBox, withBox } from '@/lib/agent-worker-proxy'; + +export const GET = async () => + await withBox( + async (username) => await proxyBox(username, 'tree', { method: 'GET' }), + );