feat(core): Implement lifecycle hooks to support streaming responses (no-changelog) (#16391)

This commit is contained in:
Benjamin Schroth
2025-06-24 15:38:03 +02:00
committed by GitHub
parent c4a50df824
commit 1086914080
19 changed files with 752 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
import type {
AINodeConnectionType,
CallbackManager,
ChunkType,
CloseFunction,
IDataObject,
IExecuteData,
IExecuteFunctions,
IExecuteResponsePromiseData,
@@ -13,6 +15,7 @@ import type {
IWorkflowExecuteAdditionalData,
NodeExecutionHint,
Result,
StructuredChunk,
Workflow,
WorkflowExecuteMode,
} from 'n8n-workflow';
@@ -128,6 +131,23 @@ export class ExecuteContext extends BaseExecuteContext implements IExecuteFuncti
)) as IExecuteFunctions['getNodeParameter'];
}
async sendChunk(type: ChunkType, content?: IDataObject | string): Promise<void> {
const node = this.getNode();
const metadata = {
nodeId: node.id,
nodeName: node.name,
timestamp: Date.now(),
};
const message: StructuredChunk = {
type,
content: content ? JSON.stringify(content) : undefined,
metadata,
};
await this.additionalData.hooks?.runHook('sendChunk', [message]);
}
async startJob<T = unknown, E = unknown>(
jobType: string,
settings: unknown,