mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Implement streaming response node on ChatTrigger and Webhook (no-changelog) (#16761)
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
||||
responseCodeProperty,
|
||||
responseDataProperty,
|
||||
responseModeProperty,
|
||||
responseModePropertyStreaming,
|
||||
} from './description';
|
||||
import { WebhookAuthorizationError } from './error';
|
||||
import {
|
||||
@@ -45,7 +46,9 @@ export class Webhook extends Node {
|
||||
icon: { light: 'file:webhook.svg', dark: 'file:webhook.dark.svg' },
|
||||
name: 'webhook',
|
||||
group: ['trigger'],
|
||||
version: [1, 1.1, 2],
|
||||
version: [1, 1.1, 2, 2.1],
|
||||
// Keep the default version as 2 to avoid releasing streaming in broken state
|
||||
defaultVersion: 2,
|
||||
description: 'Starts the workflow when a webhook is called',
|
||||
eventTriggerDescription: 'Waiting for you to call the Test URL',
|
||||
activationMessage: 'You can now make calls to your production webhook URL.',
|
||||
@@ -136,6 +139,7 @@ export class Webhook extends Node {
|
||||
},
|
||||
authenticationProperty(this.authPropertyName),
|
||||
responseModeProperty,
|
||||
responseModePropertyStreaming,
|
||||
{
|
||||
displayName:
|
||||
'Insert a \'Respond to Webhook\' node to control when and how you respond. <a href="https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.respondtowebhook/" target="_blank">More details</a>',
|
||||
@@ -148,6 +152,18 @@ export class Webhook extends Node {
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName:
|
||||
'Insert a node that supports streaming (e.g. \'AI Agent\') and enable streaming to stream directly to the response while the workflow is executed. <a href="https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.respondtowebhook/" target="_blank">More details</a>',
|
||||
name: 'webhookStreamingNotice',
|
||||
type: 'notice',
|
||||
displayOptions: {
|
||||
show: {
|
||||
responseMode: ['streaming'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
...responseCodeProperty,
|
||||
displayOptions: {
|
||||
@@ -179,6 +195,7 @@ export class Webhook extends Node {
|
||||
|
||||
async webhook(context: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
const { typeVersion: nodeVersion, type: nodeType } = context.getNode();
|
||||
const responseMode = context.getNodeParameter('responseMode', 'onReceived') as string;
|
||||
|
||||
if (nodeVersion >= 2 && nodeType === 'n8n-nodes-base.webhook') {
|
||||
checkResponseModeConfiguration(context);
|
||||
@@ -254,6 +271,26 @@ export class Webhook extends Node {
|
||||
: undefined,
|
||||
};
|
||||
|
||||
if (responseMode === 'streaming') {
|
||||
const res = context.getResponseObject();
|
||||
|
||||
// Set up streaming response headers
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Transfer-Encoding': 'chunked',
|
||||
'Cache-Control': 'no-cache',
|
||||
Connection: 'keep-alive',
|
||||
});
|
||||
|
||||
// Flush headers immediately
|
||||
res.flushHeaders();
|
||||
|
||||
return {
|
||||
noWebhookResponse: true,
|
||||
workflowData: prepareOutput(response),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
webhookResponse: options.responseData,
|
||||
workflowData: prepareOutput(response),
|
||||
|
||||
Reference in New Issue
Block a user