Skip to content

Node.js SDK toText() returns empty text for workflow streams and keeps moderated output after message_replace #44176

Closed

Description

@TemitopeKadri

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

dify-client 3.1.0 (Node.js SDK, sdks/nodejs-client), main @ 310ce87f9d

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

The SDK README says to "use stream.toText() to collect text" for streaming responses. toText() in sdks/nodejs-client/src/http/sse.ts only reads top-level answer / text / delta fields and appends every event. That breaks two documented stream shapes:

  1. Workflow apps return an empty string. The workflow pipeline streams its text output as text_chunk events, where the text is nested as data.text (TextChunkStreamResponse in api/core/app/entities/task_entities.py). toText() never looks there.
  2. Output moderation is appended instead of applied. message_replace carries the full replacement answer (MessageReplaceStreamResponse), and the web app sets content = messageReplace.answer. toText() appends it to the text already streamed, so the moderated output is still returned.

Minimal repro with the SDK's own stream helper (no server needed):

import { Readable } from 'node:stream'
import { createSseStream } from './src/http/sse'

const workflow = Readable.from([
  'data: {"event":"text_chunk","data":{"text":"Hello"}}\n\n',
  'data: {"event":"text_chunk","data":{"text":" world"}}\n\n',
])
console.log(JSON.stringify(await createSseStream(workflow, { status: 200, headers: {} }).toText()))
// ""

const moderated = Readable.from([
  'data: {"event":"message","answer":"unsafe output"}\n\n',
  'data: {"event":"message_replace","answer":"Sorry, I cannot answer that.","reason":"output_moderation"}\n\n',
])
console.log(JSON.stringify(await createSseStream(moderated, { status: 200, headers: {} }).toText()))
// "unsafe outputSorry, I cannot answer that."

Against a real server, the same happens with await (await client.runWorkflow(inputs, user, true)).toText() on a workflow app, and with a chat app that has output moderation enabled.

✔️ Expected Behavior

  • Workflow stream: "Hello world"
  • Moderated stream: "Sorry, I cannot answer that." (the replacement, as the web app shows it)

❌ Actual Behavior

  • Workflow stream: ""
  • Moderated stream: "unsafe outputSorry, I cannot answer that.". The text that moderation was meant to remove is still returned.

I have a small fix with regression tests and will open a PR.

Activity

  1. added
    review: low
    on Oct 15, 2026
  2. added a commit that references this issue on Oct 15, 2026
    f781e11
  3. Stream29 commented on Oct 16, 2026

    @Stream29
    Contributor

    Reproduced both issues: workflow streams return empty text, and message_replace appends instead of replacing the previous text.

    Reproduction output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    review: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions