Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions agentex-ui/app/api/agentex/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ async function proxy(

const method = req.method.toUpperCase();
const hasBody = method !== 'GET' && method !== 'HEAD';
const upstream = await fetch(target, {
method,
headers,
body: hasBody ? req.body : undefined,
redirect: 'manual',
// @ts-expect-error `duplex` is required to stream a request body (undici)
duplex: 'half',
});
let upstream: Response;
try {
upstream = await fetch(target, {
method,
headers,
body: hasBody ? req.body : undefined,
redirect: 'manual',
// A client disconnect must tear down the upstream request; undici otherwise holds it
// open and the upstream handler keeps running.
signal: req.signal,
// @ts-expect-error `duplex` is required to stream a request body (undici)
duplex: 'half',
});
} catch (error) {
// The disconnect above aborts `req.signal`, which rejects the fetch — not an upstream failure.
if (req.signal.aborted) return new Response(null, { status: 499 });
throw error;
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.

// Pass the upstream body through unbuffered so SSE / streaming responses work.
const resHeaders = new Headers(upstream.headers);
Expand Down
Loading