Skip to content

Commit

Permalink
feat(AI Transform Node): New node (#10405)
Browse files Browse the repository at this point in the history
Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 5ed2a77 commit 4d222ac
Show file tree
Hide file tree
Showing 24 changed files with 839 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export class ManualChatTrigger implements INodeType {
name: 'openChat',
type: 'button',
typeOptions: {
action: 'openChat',
buttonConfig: {
action: 'openChat',
},
},
default: '',
},
Expand Down
26 changes: 25 additions & 1 deletion packages/cli/src/controllers/dynamicNodeParameters.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { INodePropertyOptions } from 'n8n-workflow';
import type { INodePropertyOptions, NodeParameterValueType } from 'n8n-workflow';

import { Post, RestController } from '@/decorators';
import { getBase } from '@/WorkflowExecuteAdditionalData';
Expand Down Expand Up @@ -92,4 +92,28 @@ export class DynamicNodeParametersController {
credentials,
);
}

@Post('/action-result')
async getActionResult(
req: DynamicNodeParametersRequest.ActionResult,
): Promise<NodeParameterValueType> {
const { currentNodeParameters, nodeTypeAndVersion, path, credentials, handler, payload } =
req.body;

const additionalData = await getBase(req.user.id, currentNodeParameters);

if (handler) {
return await this.service.getActionResult(
handler,
path,
additionalData,
nodeTypeAndVersion,
currentNodeParameters,
payload,
credentials,
);
}

return;
}
}
6 changes: 6 additions & 0 deletions packages/cli/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ export declare namespace DynamicNodeParametersRequest {
type ResourceMapperFields = BaseRequest<{
methodName: string;
}>;

/** POST /dynamic-node-parameters/action-result */
type ActionResult = BaseRequest<{
handler: string;
payload: IDataObject | string | undefined;
}>;
}

// ----------------------------------
Expand Down
27 changes: 26 additions & 1 deletion packages/cli/src/services/dynamicNodeParameters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {
INodeCredentials,
INodeParameters,
INodeTypeNameVersion,
NodeParameterValueType,
IDataObject,
} from 'n8n-workflow';
import { Workflow, RoutingNode, ApplicationError } from 'n8n-workflow';
import { NodeExecuteFunctions } from 'n8n-core';
Expand Down Expand Up @@ -156,6 +158,24 @@ export class DynamicNodeParametersService {
return method.call(thisArgs);
}

/** Returns the result of the action handler */
async getActionResult(
handler: string,
path: string,
additionalData: IWorkflowExecuteAdditionalData,
nodeTypeAndVersion: INodeTypeNameVersion,
currentNodeParameters: INodeParameters,
payload: IDataObject | string | undefined,
credentials?: INodeCredentials,
): Promise<NodeParameterValueType> {
const nodeType = this.getNodeType(nodeTypeAndVersion);
const method = this.getMethod('actionHandler', handler, nodeType);
const workflow = this.getWorkflow(nodeTypeAndVersion, currentNodeParameters, credentials);
const thisArgs = this.getThisArg(path, additionalData, workflow);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return method.call(thisArgs, payload);
}

private getMethod(
type: 'resourceMapping',
methodName: string,
Expand All @@ -175,9 +195,14 @@ export class DynamicNodeParametersService {
methodName: string,
nodeType: INodeType,
): (this: ILoadOptionsFunctions) => Promise<INodePropertyOptions[]>;
private getMethod(
type: 'actionHandler',
methodName: string,
nodeType: INodeType,
): (this: ILoadOptionsFunctions, payload?: string) => Promise<NodeParameterValueType>;

private getMethod(
type: 'resourceMapping' | 'listSearch' | 'loadOptions',
type: 'resourceMapping' | 'listSearch' | 'loadOptions' | 'actionHandler',
methodName: string,
nodeType: INodeType,
) {
Expand Down
5 changes: 5 additions & 0 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,11 @@ export declare namespace DynamicNodeParameters {
interface ResourceMapperFieldsRequest extends BaseRequest {
methodName: string;
}

interface ActionResultRequest extends BaseRequest {
handler: string;
payload: IDataObject | string | undefined;
}
}

export interface EnvironmentVariable {
Expand Down
13 changes: 13 additions & 0 deletions packages/editor-ui/src/api/nodeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
INodePropertyOptions,
INodeTypeDescription,
INodeTypeNameVersion,
NodeParameterValueType,
ResourceMapperFields,
} from 'n8n-workflow';
import axios from 'axios';
Expand Down Expand Up @@ -57,3 +58,15 @@ export async function getResourceMapperFields(
sendData,
);
}

export async function getNodeParameterActionResult(
context: IRestApiContext,
sendData: DynamicNodeParameters.ActionResultRequest,
): Promise<NodeParameterValueType> {
return await makeRestApiRequest(
context,
'POST',
'/dynamic-node-parameters/action-result',
sendData,
);
}
Loading

0 comments on commit 4d222ac

Please sign in to comment.