Cannot remove workflow and node information to be sent to the frontend. #35

Closed
opened 2026-02-16 10:15:54 -05:00 by yindo · 1 comment
Owner

Originally created by @racerxdl on GitHub (Jul 15, 2024).

Currently there is no option to eat the node/workflow events from getting to the frontend.

Originally created by @racerxdl on GitHub (Jul 15, 2024). Currently there is no option to eat the node/workflow events from getting to the frontend.
yindo closed this issue 2026-02-16 10:15:54 -05:00
Author
Owner

@racerxdl commented on GitHub (Aug 7, 2024):

@iamjoel that does not actually fix it, since events are still sent to the frontend with SSE. The events should not be sent, as it can leak some private data, prompts, overview of the flow.

The way I solved locally was to edit route.ts and instead of:

return new Response(res.data as any)

do

  const reader = res.data;
  const decoder = new TextDecoder('utf-8')
  let buffer = ''

  const out = new ReadableStream({
    start(controller) {
      reader.on('data', (data: any) => {
        buffer += decoder.decode(data, { stream: true });
        const lines = buffer.split('\n')
        for (const message of lines) {
          if (lines.indexOf(message) == lines.length - 1) // Skip last, since it can be broken
            break;

          try {
            let send = true;
            if (message.startsWith('data: ')) {
              const pack = JSON.parse(message.substring(6));
              if (pack.event.startsWith('node_') || pack.event.startsWith('workflow_')) {
                send = false;
                //console.log(`Skipping send ${message}`)
              }
            } else if (!message.startsWith('event: '))
              send = false;

            if (message.trim().length && send) {
              controller.enqueue("\n")
              controller.enqueue(message + "\n");
            }
            buffer = buffer.substring(message.length); // Move buffer
          } catch (e) {
            break;
          }
        }
      });
      reader.on('end', () => {
        controller.close();
      })
    },
  });

  return new Response(out as any)

This filters out, but seens to eat some tokens randomly (and I'm not sure why)

@racerxdl commented on GitHub (Aug 7, 2024): @iamjoel that does not actually fix it, since events are still sent to the frontend with SSE. The events should not be sent, as it can leak some private data, prompts, overview of the flow. The way I solved locally was to edit `route.ts` and instead of: ```ts return new Response(res.data as any) ``` do ```ts const reader = res.data; const decoder = new TextDecoder('utf-8') let buffer = '' const out = new ReadableStream({ start(controller) { reader.on('data', (data: any) => { buffer += decoder.decode(data, { stream: true }); const lines = buffer.split('\n') for (const message of lines) { if (lines.indexOf(message) == lines.length - 1) // Skip last, since it can be broken break; try { let send = true; if (message.startsWith('data: ')) { const pack = JSON.parse(message.substring(6)); if (pack.event.startsWith('node_') || pack.event.startsWith('workflow_')) { send = false; //console.log(`Skipping send ${message}`) } } else if (!message.startsWith('event: ')) send = false; if (message.trim().length && send) { controller.enqueue("\n") controller.enqueue(message + "\n"); } buffer = buffer.substring(message.length); // Move buffer } catch (e) { break; } } }); reader.on('end', () => { controller.close(); }) }, }); return new Response(out as any) ``` This filters out, but seens to eat some tokens randomly (and I'm not sure why)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/webapp-conversation#35