mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(AI Agent Node): Implement streaming on AI agent node (no-changelog) (#16897)
This commit is contained in:
@@ -131,6 +131,21 @@ export class ExecuteContext extends BaseExecuteContext implements IExecuteFuncti
|
||||
)) as IExecuteFunctions['getNodeParameter'];
|
||||
}
|
||||
|
||||
isStreaming(): boolean {
|
||||
// Check if we have sendChunk handlers
|
||||
const handlers = this.additionalData.hooks?.handlers?.sendChunk?.length;
|
||||
const hasHandlers = handlers !== undefined && handlers > 0;
|
||||
|
||||
// Check if streaming was enabled for this execution
|
||||
const streamingEnabled = this.additionalData.streamingEnabled === true;
|
||||
|
||||
// Check current execution mode supports streaming
|
||||
const executionModeSupportsStreaming = ['manual', 'webhook', 'integrated'];
|
||||
const isStreamingMode = executionModeSupportsStreaming.includes(this.mode);
|
||||
|
||||
return hasHandlers && isStreamingMode && streamingEnabled;
|
||||
}
|
||||
|
||||
async sendChunk(type: ChunkType, content?: IDataObject | string): Promise<void> {
|
||||
const node = this.getNode();
|
||||
const metadata = {
|
||||
@@ -139,9 +154,11 @@ export class ExecuteContext extends BaseExecuteContext implements IExecuteFuncti
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
const parsedContent = typeof content === 'string' ? content : JSON.stringify(content);
|
||||
|
||||
const message: StructuredChunk = {
|
||||
type,
|
||||
content: content ? JSON.stringify(content) : undefined,
|
||||
content: parsedContent,
|
||||
metadata,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user