sbklS
Convex Community13mo ago
1 reply
sbkl

http actions with abort signal

I am using the ai package from vercel and stream some llm output. I want to handle client disconnection with the abortSignal property when the user reloads the browser manually but it seems that convex http actions don't support it at the moment? I am using http actions with hono. Getting this error:

"Not implemented: get signal for Request. Consider calling an action defined in Node.js instead (https://docs.convex.dev/functions/actions)."

import { streamText } from "ai";

app.post(
  "/api/stream",
  async (ctx) => {

    const signal = ctx.req.raw.signal;

    signal.addEventListener("abort", async (data) => {
      console.log("Stream aborted by client", sectionId, data);
    });

    const result = streamText({
      model: model,
      system,
      prompt,
      abortSignal: signal,
      onFinish: async ({ usage, text, ...rest }) => {
        // Handle end of streaming
      },
    });

    return result.toDataStreamResponse();
  },
);
Actions can call third party services to do things such as processing a payment
Actions | Convex Developer Hub
Was this page helpful?