Skip to content

Commit

Permalink
feat(core): Extract AI Tool related changes to core
Browse files Browse the repository at this point in the history
Co-authored-by: Oleg Ivaniv <[email protected]>
Co-authored-by: Alex Grozav <[email protected]>
  • Loading branch information
3 people committed Sep 29, 2023
1 parent d1b6c7f commit 46a80c1
Show file tree
Hide file tree
Showing 94 changed files with 6,244 additions and 712 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/ActiveWorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
},
executionData: {
contextData: {},
metadata: {},
nodeExecutionStack,
waitingExecution: {},
waitingExecutionSource: {},
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/GenericHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export async function createErrorExecution(
},
executionData: {
contextData: {},
metadata: {},
nodeExecutionStack: [
{
node,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export class Server extends AbstractServer {
urlBaseWebhook,
urlBaseEditor: instanceBaseUrl,
versionCli: '',
isBetaRelease: config.getEnv('generic.isBetaRelease'),
oauthCallbackUrls: {
oauth1: `${instanceBaseUrl}/${this.restEndpoint}/oauth1-credential/callback`,
oauth2: `${instanceBaseUrl}/${this.restEndpoint}/oauth2-credential/callback`,
Expand Down
15 changes: 5 additions & 10 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type {
IWorkflowExecuteProcess,
IWorkflowExecutionDataProcess,
IWorkflowErrorData,
IPushDataType,
ExecutionPayload,
} from '@/Interfaces';
import { NodeTypes } from '@/NodeTypes';
Expand Down Expand Up @@ -369,6 +370,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
},
executionData: {
contextData: {},
metadata: {},
nodeExecutionStack: [],
waitingExecution: {},
waitingExecutionSource: {},
Expand Down Expand Up @@ -709,6 +711,7 @@ export async function getRunData(
},
executionData: {
contextData: {},
metadata: {},
nodeExecutionStack,
waitingExecution: {},
waitingExecutionSource: {},
Expand Down Expand Up @@ -951,8 +954,7 @@ export function setExecutionStatus(status: ExecutionStatus) {
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function sendMessageToUI(source: string, messages: any[]) {
export function sendDataToUI(type: string, data: IDataObject | IDataObject[]) {
const { sessionId } = this;
if (sessionId === undefined) {
return;
Expand All @@ -961,14 +963,7 @@ export function sendMessageToUI(source: string, messages: any[]) {
// Push data to session which started workflow
try {
const pushInstance = Container.get(Push);
pushInstance.send(
'sendConsoleMessage',
{
source: `[Node: "${source}"]`,
messages,
},
sessionId,
);
pushInstance.send(type as IPushDataType, data, sessionId);
} catch (error) {
Logger.warn(`There was a problem sending message to UI: ${error.message}`);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/WorkflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function generateFailedExecutionFromError(
},
executionData: {
contextData: {},
metadata: {},
nodeExecutionStack: [
{
node,
Expand Down Expand Up @@ -252,6 +253,7 @@ export async function executeErrorWorkflow(
},
executionData: {
contextData: {},
metadata: {},
nodeExecutionStack,
waitingExecution: {},
waitingExecutionSource: {},
Expand Down
13 changes: 6 additions & 7 deletions packages/cli/src/WorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class WorkflowRunner {
executionId,
});

additionalData.sendMessageToUI = WorkflowExecuteAdditionalData.sendMessageToUI.bind({
additionalData.sendDataToUI = WorkflowExecuteAdditionalData.sendDataToUI.bind({
sessionId: data.sessionId,
});

Expand All @@ -344,8 +344,7 @@ export class WorkflowRunner {
} else if (
data.runData === undefined ||
data.startNodes === undefined ||
data.startNodes.length === 0 ||
data.destinationNode === undefined
data.startNodes.length === 0
) {
Logger.debug(`Execution ID ${executionId} will run executing all nodes.`, { executionId });
// Execute all nodes
Expand Down Expand Up @@ -736,11 +735,11 @@ export class WorkflowRunner {
if (responsePromise) {
responsePromise.resolve(WebhookHelpers.decodeWebhookResponse(message.data.response));
}
} else if (message.type === 'sendMessageToUI') {
} else if (message.type === 'sendDataToUI') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
WorkflowExecuteAdditionalData.sendMessageToUI.bind({ sessionId: data.sessionId })(
message.data.source,
message.data.message,
WorkflowExecuteAdditionalData.sendDataToUI.bind({ sessionId: data.sessionId })(
message.data.type,
message.data.data,
);
} else if (message.type === 'processError') {
clearTimeout(executionTimeout);
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/WorkflowRunnerProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ class WorkflowRunnerProcess {
executionId: inputData.executionId,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
additionalData.sendMessageToUI = async (source: string, message: any) => {
additionalData.sendDataToUI = async (type: string, data: IDataObject | IDataObject[]) => {
if (workflowRunner.data!.executionMode !== 'manual') {
return;
}

try {
await sendToParentProcess('sendMessageToUI', { source, message });
await sendToParentProcess('sendDataToUI', { type, data });
} catch (error) {
ErrorReporter.error(error);
this.logger.error(
Expand Down Expand Up @@ -291,8 +291,7 @@ class WorkflowRunnerProcess {
if (
this.data.runData === undefined ||
this.data.startNodes === undefined ||
this.data.startNodes.length === 0 ||
this.data.destinationNode === undefined
this.data.startNodes.length === 0
) {
// Execute all nodes

Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ export const schema = {
format: ['main', 'webhook', 'worker'] as const,
default: 'main',
},

isBetaRelease: {
doc: 'If it is a beta release',
format: 'Boolean',
default: false,
env: 'IS_BETA_RELEASE',
},
},

// How n8n can be reached (Editor & REST-API)
Expand Down
Loading

0 comments on commit 46a80c1

Please sign in to comment.