(req: NextRequest)
| 3 | import {NextRequest} from 'next/server'; |
| 4 | |
| 5 | export async function POST(req: NextRequest) { |
| 6 | const runOptions = await req.json(); |
| 7 | |
| 8 | // 1. Initiate the Pipe. |
| 9 | const pipe = new Pipe(pipeSummary()); |
| 10 | |
| 11 | // 2. Run the Pipe. |
| 12 | try { |
| 13 | const {stream, threadId} = await pipe.run(runOptions); |
| 14 | // 3. Return the ReadableStream directly with the threadId in the headers |
| 15 | // to be used on the client side to mainain a single chat thread. |
| 16 | return new Response(stream, { |
| 17 | status: 200, |
| 18 | headers: { |
| 19 | 'lb-thread-id': threadId ?? '', |
| 20 | }, |
| 21 | }); |
| 22 | } catch (error: any) { |
| 23 | return new Response( |
| 24 | JSON.stringify({ |
| 25 | error, |
| 26 | }), |
| 27 | { |
| 28 | status: error.status || 500, |
| 29 | headers: { |
| 30 | 'Content-Type': 'application/json', |
| 31 | }, |
| 32 | }, |
| 33 | ); |
| 34 | } |
| 35 | } |
nothing calls this directly
no test coverage detected