-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathroute.ts
More file actions
30 lines (22 loc) · 804 Bytes
/
route.ts
File metadata and controls
30 lines (22 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { start, getRun } from "workflow/api";
import { runCode } from "@/workflows/code-runner";
import { NextResponse } from "next/server";
export async function POST(request: Request) {
const { prompt } = await request.json();
const run = await start(runCode, [prompt]);
return NextResponse.json({ runId: run.runId });
}
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const runId = searchParams.get("runId");
if (!runId) {
return NextResponse.json({ error: "Missing runId" }, { status: 400 });
}
const run = getRun(runId);
const status = await run.status;
if (status === "completed") {
const output = await run.returnValue;
return NextResponse.json({ status, output });
}
return NextResponse.json({ status });
}