n8n-nodes-simple 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/dist/credentials/SimpleOpenAiApi.credentials.d.ts +13 -0
- package/dist/credentials/SimpleOpenAiApi.credentials.js +54 -0
- package/dist/credentials/SimpleOpenAiApi.credentials.js.map +1 -0
- package/dist/credentials/gradientOpenAi.svg +9 -0
- package/dist/nodes/CoreAgent/CoreAgent.node.d.ts +10 -0
- package/dist/nodes/CoreAgent/CoreAgent.node.js +31 -0
- package/dist/nodes/CoreAgent/CoreAgent.node.js.map +1 -0
- package/dist/nodes/Subagent/Subagent.node.d.ts +11 -0
- package/dist/nodes/Subagent/Subagent.node.js +36 -0
- package/dist/nodes/Subagent/Subagent.node.js.map +1 -0
- package/dist/nodes/shared/actions/asTool.d.ts +2 -0
- package/dist/nodes/shared/actions/asTool.js +87 -0
- package/dist/nodes/shared/actions/asTool.js.map +1 -0
- package/dist/nodes/shared/actions/message.operation.d.ts +2 -0
- package/dist/nodes/shared/actions/message.operation.js +200 -0
- package/dist/nodes/shared/actions/message.operation.js.map +1 -0
- package/dist/nodes/shared/actions/router.d.ts +2 -0
- package/dist/nodes/shared/actions/router.js +76 -0
- package/dist/nodes/shared/actions/router.js.map +1 -0
- package/dist/nodes/shared/createNodeTypeDescription.d.ts +2 -0
- package/dist/nodes/shared/createNodeTypeDescription.js +83 -0
- package/dist/nodes/shared/createNodeTypeDescription.js.map +1 -0
- package/dist/nodes/shared/gradientRobot.svg +11 -0
- package/dist/nodes/shared/gradientRobotRed.svg +11 -0
- package/dist/nodes/shared/helpers/api/apiRequest.d.ts +10 -0
- package/dist/nodes/shared/helpers/api/apiRequest.js +23 -0
- package/dist/nodes/shared/helpers/api/apiRequest.js.map +1 -0
- package/dist/nodes/shared/helpers/api/errorHandling.d.ts +4 -0
- package/dist/nodes/shared/helpers/api/errorHandling.js +31 -0
- package/dist/nodes/shared/helpers/api/errorHandling.js.map +1 -0
- package/dist/nodes/shared/helpers/api/interfaces.d.ts +37 -0
- package/dist/nodes/shared/helpers/api/interfaces.js +3 -0
- package/dist/nodes/shared/helpers/api/interfaces.js.map +1 -0
- package/dist/nodes/shared/helpers/api/utils.d.ts +5 -0
- package/dist/nodes/shared/helpers/api/utils.js +42 -0
- package/dist/nodes/shared/helpers/api/utils.js.map +1 -0
- package/dist/nodes/shared/helpers/asCoreNode/chatHistoryUnpacker.d.ts +6 -0
- package/dist/nodes/shared/helpers/asCoreNode/chatHistoryUnpacker.js +64 -0
- package/dist/nodes/shared/helpers/asCoreNode/chatHistoryUnpacker.js.map +1 -0
- package/dist/nodes/shared/helpers/asCoreNode/chatUnpacker.d.ts +6 -0
- package/dist/nodes/shared/helpers/asCoreNode/chatUnpacker.js +62 -0
- package/dist/nodes/shared/helpers/asCoreNode/chatUnpacker.js.map +1 -0
- package/dist/nodes/shared/helpers/asCoreNode/constants.d.ts +1 -0
- package/dist/nodes/shared/helpers/asCoreNode/constants.js +26 -0
- package/dist/nodes/shared/helpers/asCoreNode/constants.js.map +1 -0
- package/dist/nodes/shared/helpers/asCoreNode/messageModel.d.ts +43 -0
- package/dist/nodes/shared/helpers/asCoreNode/messageModel.js +12 -0
- package/dist/nodes/shared/helpers/asCoreNode/messageModel.js.map +1 -0
- package/dist/nodes/shared/helpers/asCoreNode/stepsExtractor.d.ts +6 -0
- package/dist/nodes/shared/helpers/asCoreNode/stepsExtractor.js +27 -0
- package/dist/nodes/shared/helpers/asCoreNode/stepsExtractor.js.map +1 -0
- package/dist/nodes/shared/helpers/asTool/customFields.d.ts +18 -0
- package/dist/nodes/shared/helpers/asTool/customFields.js +24 -0
- package/dist/nodes/shared/helpers/asTool/customFields.js.map +1 -0
- package/dist/nodes/shared/helpers/asTool/subagentTool.d.ts +11 -0
- package/dist/nodes/shared/helpers/asTool/subagentTool.js +56 -0
- package/dist/nodes/shared/helpers/asTool/subagentTool.js.map +1 -0
- package/dist/nodes/shared/helpers/asTool/toolSchemaParsing.d.ts +6 -0
- package/dist/nodes/shared/helpers/asTool/toolSchemaParsing.js +23 -0
- package/dist/nodes/shared/helpers/asTool/toolSchemaParsing.js.map +1 -0
- package/dist/nodes/shared/helpers/asToolUser/N8nTool.d.ts +9 -0
- package/dist/nodes/shared/helpers/asToolUser/N8nTool.js +91 -0
- package/dist/nodes/shared/helpers/asToolUser/N8nTool.js.map +1 -0
- package/dist/nodes/shared/helpers/asToolUser/langchainHelpers.d.ts +3 -0
- package/dist/nodes/shared/helpers/asToolUser/langchainHelpers.js +28 -0
- package/dist/nodes/shared/helpers/asToolUser/langchainHelpers.js.map +1 -0
- package/dist/nodes/shared/methods/index.d.ts +1 -0
- package/dist/nodes/shared/methods/index.js +38 -0
- package/dist/nodes/shared/methods/index.js.map +1 -0
- package/dist/nodes/shared/methods/listSearch.d.ts +2 -0
- package/dist/nodes/shared/methods/listSearch.js +34 -0
- package/dist/nodes/shared/methods/listSearch.js.map +1 -0
- package/dist/nodes/shared/properties.d.ts +2 -0
- package/dist/nodes/shared/properties.js +480 -0
- package/dist/nodes/shared/properties.js.map +1 -0
- package/dist/package.json +74 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# n8n-nodes-_node-name_
|
|
2
|
+
|
|
3
|
+
This is an n8n community node. It lets you use _app/service name_ in your n8n workflows.
|
|
4
|
+
|
|
5
|
+
_App/service name_ is _one or two sentences describing the service this node integrates with_.
|
|
6
|
+
|
|
7
|
+
[n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/reference/license/) workflow automation platform.
|
|
8
|
+
|
|
9
|
+
[Installation](#installation)
|
|
10
|
+
[Operations](#operations)
|
|
11
|
+
[Credentials](#credentials) <!-- delete if no auth needed -->
|
|
12
|
+
[Compatibility](#compatibility)
|
|
13
|
+
[Usage](#usage) <!-- delete if not using this section -->
|
|
14
|
+
[Resources](#resources)
|
|
15
|
+
[Version history](#version-history) <!-- delete if not using this section -->
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation.
|
|
20
|
+
|
|
21
|
+
## Operations
|
|
22
|
+
|
|
23
|
+
_List the operations supported by your node._
|
|
24
|
+
|
|
25
|
+
## Credentials
|
|
26
|
+
|
|
27
|
+
_If users need to authenticate with the app/service, provide details here. You should include prerequisites (such as signing up with the service), available authentication methods, and how to set them up._
|
|
28
|
+
|
|
29
|
+
## Compatibility
|
|
30
|
+
|
|
31
|
+
_State the minimum n8n version, as well as which versions you test against. You can also include any known version incompatibility issues._
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
_This is an optional section. Use it to help users with any difficult or confusing aspects of the node._
|
|
36
|
+
|
|
37
|
+
_By the time users are looking for community nodes, they probably already know n8n basics. But if you expect new users, you can link to the [Try it out](https://docs.n8n.io/try-it-out/) documentation to help them get started._
|
|
38
|
+
|
|
39
|
+
## Resources
|
|
40
|
+
|
|
41
|
+
* [n8n community nodes documentation](https://docs.n8n.io/integrations/community-nodes/)
|
|
42
|
+
* _Link to app/service documentation._
|
|
43
|
+
|
|
44
|
+
## Version history
|
|
45
|
+
|
|
46
|
+
_This is another optional section. If your node has multiple versions, include a short description of available versions and what changed, as well as any compatibility impact._
|
|
47
|
+
|
|
48
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
export declare class SimpleOpenAiApi implements ICredentialType {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
documentationUrl: string;
|
|
6
|
+
icon: {
|
|
7
|
+
readonly light: "file:gradientOpenAi.svg";
|
|
8
|
+
readonly dark: "file:gradientOpenAi.svg";
|
|
9
|
+
};
|
|
10
|
+
properties: INodeProperties[];
|
|
11
|
+
authenticate: IAuthenticateGeneric;
|
|
12
|
+
test: ICredentialTestRequest;
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleOpenAiApi = void 0;
|
|
4
|
+
class SimpleOpenAiApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = 'simpleOpenAiApi';
|
|
7
|
+
this.displayName = 'Simple OpenAI API';
|
|
8
|
+
this.documentationUrl = 'https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/text-operations/#message-a-model';
|
|
9
|
+
this.icon = { light: 'file:gradientOpenAi.svg', dark: 'file:gradientOpenAi.svg' };
|
|
10
|
+
this.properties = [
|
|
11
|
+
{
|
|
12
|
+
displayName: 'API Key',
|
|
13
|
+
name: 'apiKey',
|
|
14
|
+
type: 'string',
|
|
15
|
+
typeOptions: { password: true },
|
|
16
|
+
required: true,
|
|
17
|
+
default: '',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
displayName: 'Base URL',
|
|
21
|
+
name: 'baseUrl',
|
|
22
|
+
type: 'string',
|
|
23
|
+
required: true,
|
|
24
|
+
default: 'https://api.openai.com/v1',
|
|
25
|
+
description: "Base URL for the API.",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
displayName: 'Organization ID (optional)',
|
|
29
|
+
name: 'organizationId',
|
|
30
|
+
type: 'string',
|
|
31
|
+
default: '',
|
|
32
|
+
hint: 'Only required if you belong to multiple organisations',
|
|
33
|
+
description: "For users who belong to multiple organizations, you can set which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.",
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
this.authenticate = {
|
|
37
|
+
type: 'generic',
|
|
38
|
+
properties: {
|
|
39
|
+
headers: {
|
|
40
|
+
Authorization: '=Bearer {{$credentials.apiKey}}',
|
|
41
|
+
'OpenAI-Organization': '={{$credentials.organizationId}}',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
this.test = {
|
|
46
|
+
request: {
|
|
47
|
+
baseURL: '={{$credentials.baseUrl}}',
|
|
48
|
+
url: '/models',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SimpleOpenAiApi = SimpleOpenAiApi;
|
|
54
|
+
//# sourceMappingURL=SimpleOpenAiApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleOpenAiApi.credentials.js","sourceRoot":"","sources":["../../credentials/SimpleOpenAiApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,eAAe;IAA5B;QACC,SAAI,GAAG,iBAAiB,CAAC;QAEzB,gBAAW,GAAG,mBAAmB,CAAC;QAElC,qBAAgB,GAAG,gHAAgH,CAAC;QAEpI,SAAI,GAAG,EAAE,KAAK,EAAE,yBAAyB,EAAE,IAAI,EAAE,yBAAyB,EAAW,CAAC;QAEtF,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,SAAS;gBACtB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAE;aACX;YACD;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,2BAA2B;gBACpC,WAAW,EACV,uBAAuB;aACxB;YACD;gBACC,WAAW,EAAE,4BAA4B;gBACzC,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,IAAI,EAAE,uDAAuD;gBAC7D,WAAW,EACV,8MAA8M;aAC/M;SACD,CAAC;QAEF,iBAAY,GAAyB;YACpC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE;gBACX,OAAO,EAAE;oBACR,aAAa,EAAE,iCAAiC;oBAChD,qBAAqB,EAAE,kCAAkC;iBACzD;aACD;SACD,CAAC;QAEF,SAAI,GAA2B;YAC9B,OAAO,EAAE;gBACR,OAAO,EAAE,2BAA2B;gBACpC,GAAG,EAAE,SAAS;aACd;SACD,CAAC;IACH,CAAC;CAAA;AAtDD,0CAsDC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="260" preserveAspectRatio="xMidYMid" viewBox="0 0 256 260">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="gradient-bl-tr" x1="0%" y1="100%" x2="100%" y2="0%">
|
|
4
|
+
<stop offset="0%" stop-color="#a857fd" />
|
|
5
|
+
<stop offset="100%" stop-color="#60c5d1" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<path d="M239.184 106.203a64.72 64.72 0 0 0-5.576-53.103C219.452 28.459 191 15.784 163.213 21.74A65.586 65.586 0 0 0 52.096 45.22a64.72 64.72 0 0 0-43.23 31.36c-14.31 24.602-11.061 55.634 8.033 76.74a64.67 64.67 0 0 0 5.525 53.102c14.174 24.65 42.644 37.324 70.446 31.36a64.72 64.72 0 0 0 48.754 21.744c28.481.025 53.714-18.361 62.414-45.481a64.77 64.77 0 0 0 43.229-31.36c14.137-24.558 10.875-55.423-8.083-76.483m-97.56 136.338a48.4 48.4 0 0 1-31.105-11.255l1.535-.87 51.67-29.825a8.6 8.6 0 0 0 4.247-7.367v-72.85l21.845 12.636c.218.111.37.32.409.563v60.367c-.056 26.818-21.783 48.545-48.601 48.601M37.158 197.93a48.35 48.35 0 0 1-5.781-32.589l1.534.921 51.722 29.826a8.34 8.34 0 0 0 8.441 0l63.181-36.425v25.221a.87.87 0 0 1-.358.665l-52.335 30.184c-23.257 13.398-52.97 5.431-66.404-17.803M23.549 85.38a48.5 48.5 0 0 1 25.58-21.333v61.39a8.29 8.29 0 0 0 4.195 7.316l62.874 36.272-21.845 12.636a.82.82 0 0 1-.767 0L41.353 151.53c-23.211-13.454-31.171-43.144-17.804-66.405zm179.466 41.695-63.08-36.63L161.73 77.86a.82.82 0 0 1 .768 0l52.233 30.184a48.6 48.6 0 0 1-7.316 87.635v-61.391a8.54 8.54 0 0 0-4.4-7.213m21.742-32.69-1.535-.922-51.619-30.081a8.39 8.39 0 0 0-8.492 0L99.98 99.808V74.587a.72.72 0 0 1 .307-.665l52.233-30.133a48.652 48.652 0 0 1 72.236 50.391zM88.061 139.097l-21.845-12.585a.87.87 0 0 1-.41-.614V65.685a48.652 48.652 0 0 1 79.757-37.346l-1.535.87-51.67 29.825a8.6 8.6 0 0 0-4.246 7.367zm11.868-25.58L128.067 97.3l28.188 16.218v32.434l-28.086 16.218-28.188-16.218z" fill="url(#gradient-bl-tr)" />
|
|
9
|
+
</svg>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IExecuteFunctions, type INodeType, type INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
import { listSearch } from '../shared/methods';
|
|
3
|
+
export declare class CoreAgent implements INodeType {
|
|
4
|
+
description: INodeTypeDescription;
|
|
5
|
+
constructor();
|
|
6
|
+
methods: {
|
|
7
|
+
listSearch: typeof listSearch;
|
|
8
|
+
};
|
|
9
|
+
execute(this: IExecuteFunctions): Promise<import("n8n-workflow").INodeExecutionData[][]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreAgent = void 0;
|
|
4
|
+
const createNodeTypeDescription_1 = require("../shared/createNodeTypeDescription");
|
|
5
|
+
const router_1 = require("../shared/actions/router");
|
|
6
|
+
const methods_1 = require("../shared/methods");
|
|
7
|
+
class CoreAgent {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.methods = {
|
|
10
|
+
listSearch: methods_1.listSearch,
|
|
11
|
+
};
|
|
12
|
+
this.description = (0, createNodeTypeDescription_1.createNodeTypeDescription)('coreAgent', {
|
|
13
|
+
displayName: 'AI Agent',
|
|
14
|
+
defaults: { name: 'AI Agent' },
|
|
15
|
+
description: 'Agent capable of using tools, subagents, and structured output.',
|
|
16
|
+
icon: { light: 'file:../shared/gradientRobot.svg', dark: 'file:../shared/gradientRobot.svg' },
|
|
17
|
+
codex: {
|
|
18
|
+
alias: ['Special', 'General', 'AI', 'Agent', 'Subagent', 'OpenAI', 'LiteLLM', 'LangChain', 'ChatGPT', 'assistant', 'Chat', 'Conversational', 'Plan and Execute', 'ReAct'],
|
|
19
|
+
categories: ['AI'],
|
|
20
|
+
subcategories: {
|
|
21
|
+
AI: ['Agents', 'Miscellaneous', 'Root Nodes'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async execute() {
|
|
27
|
+
return await router_1.router.call(this);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.CoreAgent = CoreAgent;
|
|
31
|
+
//# sourceMappingURL=CoreAgent.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreAgent.node.js","sourceRoot":"","sources":["../../../nodes/CoreAgent/CoreAgent.node.ts"],"names":[],"mappings":";;;AAMA,mFAAgF;AAChF,qDAAkD;AAClD,+CAA+C;AAE/C,MAAa,SAAS;IAGrB;QAmBA,YAAO,GAAG;YACT,UAAU,EAAV,oBAAU;SACV,CAAC;QApBD,IAAI,CAAC,WAAW,GAAG,IAAA,qDAAyB,EAC3C,WAAW,EACX;YACC,WAAW,EAAE,UAAU;YACvB,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;YAC9B,WAAW,EAAE,iEAAiE;YAC9E,IAAI,EAAE,EAAE,KAAK,EAAE,kCAAkC,EAAE,IAAI,EAAE,kCAAkC,EAAE;YAC7F,KAAK,EAAE;gBACN,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,CAAC;gBACzK,UAAU,EAAE,CAAC,IAAI,CAAC;gBAClB,aAAa,EAAE;oBACd,EAAE,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,YAAY,CAAC;iBAC7C;aACD;SACD,CACD,CAAC;IACH,CAAC;IAOD,KAAK,CAAC,OAAO;QACZ,OAAO,MAAM,eAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CAED;AA/BD,8BA+BC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type IExecuteFunctions, type INodeType, type INodeTypeDescription, type SupplyData } from 'n8n-workflow';
|
|
2
|
+
import { listSearch } from '../shared/methods';
|
|
3
|
+
export declare class Subagent implements INodeType {
|
|
4
|
+
description: INodeTypeDescription;
|
|
5
|
+
constructor();
|
|
6
|
+
methods: {
|
|
7
|
+
listSearch: typeof listSearch;
|
|
8
|
+
};
|
|
9
|
+
execute(this: IExecuteFunctions): Promise<import("n8n-workflow").INodeExecutionData[][]>;
|
|
10
|
+
supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subagent = void 0;
|
|
4
|
+
const createNodeTypeDescription_1 = require("../shared/createNodeTypeDescription");
|
|
5
|
+
const router_1 = require("../shared/actions/router");
|
|
6
|
+
const asTool_1 = require("../shared/actions/asTool");
|
|
7
|
+
const methods_1 = require("../shared/methods");
|
|
8
|
+
class Subagent {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.methods = {
|
|
11
|
+
listSearch: methods_1.listSearch,
|
|
12
|
+
};
|
|
13
|
+
this.description = (0, createNodeTypeDescription_1.createNodeTypeDescription)('subAgent', {
|
|
14
|
+
displayName: 'AI Subagent',
|
|
15
|
+
defaults: { name: 'AI Subagent' },
|
|
16
|
+
description: 'Subagent capable of using tools and subagents.',
|
|
17
|
+
icon: { light: 'file:../shared/gradientRobot.svg', dark: 'file:../shared/gradientRobot.svg' },
|
|
18
|
+
codex: {
|
|
19
|
+
alias: ['Special', 'General', 'AI', 'Agent', 'Subagent', 'OpenAI', 'LiteLLM', 'LangChain', 'ChatGPT', 'assistant', 'Chat', 'Conversational', 'Plan and Execute', 'ReAct', 'Tools'],
|
|
20
|
+
categories: ['AI'],
|
|
21
|
+
subcategories: {
|
|
22
|
+
AI: ['Miscellaneous', 'Tools'],
|
|
23
|
+
Tools: ['Recommended Tools', 'Other Tools'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async execute() {
|
|
29
|
+
return await router_1.router.call(this);
|
|
30
|
+
}
|
|
31
|
+
async supplyData(itemIndex) {
|
|
32
|
+
return await asTool_1.executeAsTool.call(this, itemIndex);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Subagent = Subagent;
|
|
36
|
+
//# sourceMappingURL=Subagent.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subagent.node.js","sourceRoot":"","sources":["../../../nodes/Subagent/Subagent.node.ts"],"names":[],"mappings":";;;AAOA,mFAAgF;AAChF,qDAAkD;AAClD,qDAAyD;AACzD,+CAA+C;AAE/C,MAAa,QAAQ;IAGpB;QAoBA,YAAO,GAAG;YACT,UAAU,EAAV,oBAAU;SACV,CAAC;QArBD,IAAI,CAAC,WAAW,GAAG,IAAA,qDAAyB,EAC3C,UAAU,EACV;YACC,WAAW,EAAE,aAAa;YAC1B,QAAQ,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;YACjC,WAAW,EAAE,gDAAgD;YAC7D,IAAI,EAAE,EAAE,KAAK,EAAE,kCAAkC,EAAE,IAAI,EAAE,kCAAkC,EAAE;YAC7F,KAAK,EAAE;gBACN,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC;gBAClL,UAAU,EAAE,CAAC,IAAI,CAAC;gBAClB,aAAa,EAAE;oBACd,EAAE,EAAE,CAAC,eAAe,EAAE,OAAO,CAAC;oBAC9B,KAAK,EAAE,CAAC,mBAAmB,EAAE,aAAa,CAAC;iBAC3C;aACD;SACD,CACD,CAAC;IACH,CAAC;IAOD,KAAK,CAAC,OAAO;QACZ,OAAO,MAAM,eAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAGD,KAAK,CAAC,UAAU,CAA0B,SAAiB;QAC1D,OAAO,MAAM,sBAAa,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAClD,CAAC;CACD;AApCD,4BAoCC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeAsTool = executeAsTool;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const tools_1 = require("@langchain/core/tools");
|
|
6
|
+
const subagentTool_1 = require("../helpers/asTool/subagentTool");
|
|
7
|
+
const toolSchemaParsing_1 = require("../helpers/asTool/toolSchemaParsing");
|
|
8
|
+
const customFields_1 = require("../helpers/asTool/customFields");
|
|
9
|
+
async function executeAsTool(itemIndex) {
|
|
10
|
+
const name = this.getNodeParameter('name', itemIndex, 'subagent');
|
|
11
|
+
const description = this.getNodeParameter('description', itemIndex, 'Call this to message an AI subagent.');
|
|
12
|
+
const toolHandler = async (input) => {
|
|
13
|
+
const formattedInput = typeof input === 'string' ? { input } : input;
|
|
14
|
+
const { index } = this.addInputData("ai_tool", [[{ json: formattedInput }]]);
|
|
15
|
+
let response = '';
|
|
16
|
+
let executionError;
|
|
17
|
+
try {
|
|
18
|
+
const subagentTool = new subagentTool_1.SubagentTool(this);
|
|
19
|
+
response = await subagentTool._call(input);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
executionError = new n8n_workflow_1.NodeOperationError(this.getNode(), error);
|
|
23
|
+
response = `There was an error: "${executionError.message}"`;
|
|
24
|
+
}
|
|
25
|
+
if (typeof response === 'number') {
|
|
26
|
+
response = response.toString();
|
|
27
|
+
}
|
|
28
|
+
if (typeof response !== 'string') {
|
|
29
|
+
executionError = new n8n_workflow_1.NodeOperationError(this.getNode(), 'Wrong output type returned', {
|
|
30
|
+
description: `The response property should be a string, but it is an ${typeof response}`,
|
|
31
|
+
});
|
|
32
|
+
response = `There was an error: "${executionError.message}"`;
|
|
33
|
+
}
|
|
34
|
+
if (executionError) {
|
|
35
|
+
void this.addOutputData("ai_tool", index, executionError);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
void this.addOutputData("ai_tool", index, [[{ json: { response } }]]);
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
};
|
|
42
|
+
const commonToolOptions = {
|
|
43
|
+
name,
|
|
44
|
+
description,
|
|
45
|
+
func: toolHandler,
|
|
46
|
+
};
|
|
47
|
+
let tool = undefined;
|
|
48
|
+
const inputSchemaType = this.getNodeParameter('inputSchemaType', itemIndex, 'default');
|
|
49
|
+
{
|
|
50
|
+
try {
|
|
51
|
+
let parsedJsonParameters;
|
|
52
|
+
switch (inputSchemaType) {
|
|
53
|
+
case 'inputCustomFields': {
|
|
54
|
+
const inputCustomFieldsParameters = this.getNodeParameter('inputCustomFieldsParameters.values', itemIndex, []);
|
|
55
|
+
parsedJsonParameters = (0, customFields_1.convertCustomFieldsToSchema)(inputCustomFieldsParameters);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'inputJsonExample': {
|
|
59
|
+
const inputJsonExampleParameters = this.getNodeParameter('inputJsonExampleParameters', itemIndex, '');
|
|
60
|
+
parsedJsonParameters = (0, toolSchemaParsing_1.generateSchema)(inputJsonExampleParameters);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'inputJsonSchema': {
|
|
64
|
+
const inputJsonSchemaParameters = this.getNodeParameter('inputJsonSchemaParameters', itemIndex, '');
|
|
65
|
+
parsedJsonParameters = (0, n8n_workflow_1.jsonParse)(inputJsonSchemaParameters);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
default: {
|
|
69
|
+
tool = new tools_1.DynamicTool(commonToolOptions);
|
|
70
|
+
return { response: tool };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const zodSchema = (0, toolSchemaParsing_1.convertJsonSchemaToZod)(parsedJsonParameters);
|
|
74
|
+
tool = new tools_1.DynamicStructuredTool({
|
|
75
|
+
schema: zodSchema,
|
|
76
|
+
...commonToolOptions,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Error during parsing of JSON Schema. \n ' + error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
response: tool,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=asTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asTool.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/asTool.ts"],"names":[],"mappings":";;AAmBA,sCAqGC;AAxHD,+CAQsB;AAEtB,iDAA2E;AAI3E,iEAA8D;AAC9D,2EAA6F;AAC7F,iEAAwG;AAGjG,KAAK,UAAU,aAAa,CAA0B,SAAiB;IAG7E,MAAM,IAAI,GAAG,IAAI,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BAC9G,oBAAoB,GAAG,IAAA,wBAAS,EAAc,yBAAyB,CAAC,CAAC;oBACzE,MAAM;gBACP,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACT,IAAI,GAAG,IAAI,mBAAW,CAAC,iBAAiB,CAAC,CAAC;oBAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;gBAC1B,CAAC;YACF,CAAC;YAED,MAAM,SAAS,GAAG,IAAA,0CAAsB,EAAmB,oBAAoB,CAAC,CAAC;YAEjF,IAAI,GAAG,IAAI,6BAAqB,CAAC;gBAChC,MAAM,EAAE,SAAS;gBACjB,GAAG,iBAAiB;aACpB,CAAC,CAAC;QAEJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,iCAAkB,CAC3B,IAAI,CAAC,OAAO,EAAE,EACd,0CAA0C,GAAG,KAAK,CAClD,CAAC;QACH,CAAC;IACF,CAAC;IAED,OAAO;QACN,QAAQ,EAAE,IAAI;KACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.execute = execute;
|
|
7
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
8
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
9
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
10
|
+
const apiRequest_1 = require("../helpers/api/apiRequest");
|
|
11
|
+
const utils_1 = require("../helpers/api/utils");
|
|
12
|
+
const langchainHelpers_1 = require("../helpers/asToolUser/langchainHelpers");
|
|
13
|
+
const messageModel_1 = require("../helpers/asCoreNode/messageModel");
|
|
14
|
+
const stepsExtractor_1 = require("../helpers/asCoreNode/stepsExtractor");
|
|
15
|
+
const chatUnpacker_1 = require("../helpers/asCoreNode/chatUnpacker");
|
|
16
|
+
async function execute(i, parentMessageContentStr = '', parentMessageContentObj = {}) {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
18
|
+
const model = this.getNodeParameter('modelId', i, '', { extractValue: true });
|
|
19
|
+
const temperature = this.getNodeParameter('temperature', i, 1);
|
|
20
|
+
const agentType = this.getNodeParameter('agentType', i, 'coreAgent');
|
|
21
|
+
const rawMessagesToSend = this.getNodeParameter('messagesToSend.values', i, []);
|
|
22
|
+
const inputSchemaType = this.getNodeParameter('inputSchemaType', i, '');
|
|
23
|
+
const structuredOutput = this.getNodeParameter('structuredOutput', i, false);
|
|
24
|
+
const addToOutput = this.getNodeParameter('addToOutput', i, []);
|
|
25
|
+
const outputJsonSchema = this.getNodeParameter('outputJsonSchema', i, '');
|
|
26
|
+
const options = this.getNodeParameter('options', i, {});
|
|
27
|
+
const maxToolsIterations = this.getNodeParameter('options.maxToolsIterations', i, 15);
|
|
28
|
+
const customParameters = this.getNodeParameter('options.customParameters', i, '{}');
|
|
29
|
+
const abortSignal = this.getExecutionCancelSignal();
|
|
30
|
+
const memoryInput = (await this.getInputConnectionData("ai_memory", i, undefined));
|
|
31
|
+
let memory = Array.isArray(memoryInput) ? memoryInput[0] : memoryInput;
|
|
32
|
+
let messages = await (0, chatUnpacker_1.unpackChatHistoryAndMemory)(rawMessagesToSend, memory);
|
|
33
|
+
messages = messages.filter(item => item.content !== '');
|
|
34
|
+
if (inputSchemaType === 'default' && parentMessageContentStr !== '') {
|
|
35
|
+
messages.push({ role: "user", content: parentMessageContentStr });
|
|
36
|
+
}
|
|
37
|
+
else if (['inputCustomFields', 'inputJsonExample', 'inputJsonSchema'].includes(inputSchemaType) &&
|
|
38
|
+
Object.keys(parentMessageContentObj).length !== 0) {
|
|
39
|
+
messages.forEach((message) => {
|
|
40
|
+
let template = handlebars_1.default.compile(message.content);
|
|
41
|
+
message.content = template(parentMessageContentObj);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
let response_format;
|
|
45
|
+
if (structuredOutput) {
|
|
46
|
+
response_format = { type: 'json_schema', json_schema: JSON.parse(outputJsonSchema) };
|
|
47
|
+
}
|
|
48
|
+
let tools;
|
|
49
|
+
let externalTools = [];
|
|
50
|
+
const enforceUniqueNames = true;
|
|
51
|
+
externalTools = await (0, langchainHelpers_1.getConnectedTools)(this, enforceUniqueNames, false);
|
|
52
|
+
if (externalTools.length) {
|
|
53
|
+
tools = externalTools.length ? externalTools === null || externalTools === void 0 ? void 0 : externalTools.map(utils_1.formatToOpenAITool) : undefined;
|
|
54
|
+
}
|
|
55
|
+
let customParamsObj = {};
|
|
56
|
+
if (customParameters && customParameters.trim() !== '') {
|
|
57
|
+
try {
|
|
58
|
+
customParamsObj = JSON.parse(customParameters);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error('Invalid JSON in customParameters');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const cleanOptions = (0, omit_1.default)(options, [
|
|
65
|
+
'customParameters',
|
|
66
|
+
'maxToolsIterations'
|
|
67
|
+
]);
|
|
68
|
+
const body = {
|
|
69
|
+
model,
|
|
70
|
+
temperature,
|
|
71
|
+
messages,
|
|
72
|
+
tools,
|
|
73
|
+
response_format,
|
|
74
|
+
...cleanOptions,
|
|
75
|
+
...customParamsObj
|
|
76
|
+
};
|
|
77
|
+
if (!Array.isArray(messages) || !messages.every(messageModel_1.isValidMessage)) {
|
|
78
|
+
throw new Error("Invalid or missing 'messages' in the request body.");
|
|
79
|
+
}
|
|
80
|
+
const originalMessagesLength = messages.length;
|
|
81
|
+
let response = (await apiRequest_1.apiRequest.call(this, 'POST', `/chat/completions`, {
|
|
82
|
+
body,
|
|
83
|
+
}));
|
|
84
|
+
if (!response)
|
|
85
|
+
return [];
|
|
86
|
+
let toolCalls = (_b = (_a = response === null || response === void 0 ? void 0 : response.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.tool_calls;
|
|
87
|
+
let currentIteration = 1;
|
|
88
|
+
while (toolCalls === null || toolCalls === void 0 ? void 0 : toolCalls.length) {
|
|
89
|
+
if ((abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) ||
|
|
90
|
+
(maxToolsIterations > 0 && currentIteration >= maxToolsIterations)) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
messages.push(response.choices[0].message);
|
|
94
|
+
for (const toolCall of toolCalls) {
|
|
95
|
+
const functionName = toolCall.function.name;
|
|
96
|
+
const functionArgs = toolCall.function.arguments;
|
|
97
|
+
let toolMessageContent;
|
|
98
|
+
for (const tool of externalTools !== null && externalTools !== void 0 ? externalTools : []) {
|
|
99
|
+
if (tool.name === functionName) {
|
|
100
|
+
const parsedArgs = (0, n8n_workflow_1.jsonParse)(functionArgs);
|
|
101
|
+
const parentMessageContent = (_d = (_c = parsedArgs.input) !== null && _c !== void 0 ? _c : parsedArgs) !== null && _d !== void 0 ? _d : functionArgs;
|
|
102
|
+
toolMessageContent = await tool.invoke(parentMessageContent);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (typeof toolMessageContent === 'object') {
|
|
106
|
+
toolMessageContent = JSON.stringify(toolMessageContent);
|
|
107
|
+
}
|
|
108
|
+
messages.push({
|
|
109
|
+
tool_call_id: toolCall.id,
|
|
110
|
+
role: 'tool',
|
|
111
|
+
content: toolMessageContent,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
response = (await apiRequest_1.apiRequest.call(this, 'POST', `/chat/completions`, {
|
|
115
|
+
body,
|
|
116
|
+
}));
|
|
117
|
+
toolCalls = response.choices[0].message.tool_calls;
|
|
118
|
+
currentIteration += 1;
|
|
119
|
+
}
|
|
120
|
+
const outputData = [];
|
|
121
|
+
if (["subAgent", "flexAgent"].includes(agentType) && parentMessageContentStr !== '') {
|
|
122
|
+
outputData.push({
|
|
123
|
+
json: { response: response },
|
|
124
|
+
pairedItem: { item: 0 },
|
|
125
|
+
});
|
|
126
|
+
return outputData;
|
|
127
|
+
}
|
|
128
|
+
;
|
|
129
|
+
if (response_format) {
|
|
130
|
+
response.choices = response.choices.map((choice) => {
|
|
131
|
+
try {
|
|
132
|
+
choice.message.content = JSON.parse(choice.message.content);
|
|
133
|
+
}
|
|
134
|
+
catch (error) { }
|
|
135
|
+
return choice;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (addToOutput.includes("fullResponse")) {
|
|
139
|
+
outputData.push({ json: { response: response }, pairedItem: { item: i } });
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
outputData.push({ json: { response: { choices: response.choices } }, pairedItem: { item: i } });
|
|
143
|
+
}
|
|
144
|
+
const newMessages = messages.slice(originalMessagesLength);
|
|
145
|
+
if (addToOutput.includes("steps")) {
|
|
146
|
+
outputData.forEach(item => {
|
|
147
|
+
item.json.steps = (0, stepsExtractor_1.extractToolMessages)(newMessages);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (addToOutput.includes("chatHistory")) {
|
|
151
|
+
const includeStepsInChatHistory = this.getNodeParameter('includeStepsInChatHistory', i, true);
|
|
152
|
+
const includeSystemMessagesInChatHistory = this.getNodeParameter('includeSystemMessagesInChatHistory', i, true);
|
|
153
|
+
let chatHistoryMessages = structuredClone(messages);
|
|
154
|
+
if (!includeStepsInChatHistory) {
|
|
155
|
+
chatHistoryMessages = chatHistoryMessages
|
|
156
|
+
.filter(msg => msg.content !== null && msg.role !== 'tool')
|
|
157
|
+
.map(({ role, content }) => ({ role, content }));
|
|
158
|
+
}
|
|
159
|
+
if (!includeSystemMessagesInChatHistory) {
|
|
160
|
+
chatHistoryMessages = chatHistoryMessages
|
|
161
|
+
.filter(msg => msg.role !== 'system');
|
|
162
|
+
}
|
|
163
|
+
if ((_f = (_e = response === null || response === void 0 ? void 0 : response.choices) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.message) {
|
|
164
|
+
const rootMessage = {
|
|
165
|
+
role: response.choices[0].message.role,
|
|
166
|
+
content: response.choices[0].message.content,
|
|
167
|
+
};
|
|
168
|
+
chatHistoryMessages.push(rootMessage);
|
|
169
|
+
}
|
|
170
|
+
outputData.forEach(item => {
|
|
171
|
+
item.json.chat_history = chatHistoryMessages;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (addToOutput.includes("request")) {
|
|
175
|
+
outputData.forEach(item => {
|
|
176
|
+
item.json.request = body;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
outputData.forEach(item => {
|
|
180
|
+
const reordered = {
|
|
181
|
+
request: item.json.request,
|
|
182
|
+
steps: item.json.steps,
|
|
183
|
+
response: item.json.response,
|
|
184
|
+
chat_history: item.json.chat_history,
|
|
185
|
+
};
|
|
186
|
+
item.json = Object.fromEntries(Object.entries(reordered).filter(([_, value]) => value !== undefined));
|
|
187
|
+
});
|
|
188
|
+
if (memory && ((_h = (_g = response === null || response === void 0 ? void 0 : response.choices) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.message)) {
|
|
189
|
+
const lastUserMessageContent = ((_j = [...messages].reverse().find(msg => msg.role === 'user')) === null || _j === void 0 ? void 0 : _j.content) || '';
|
|
190
|
+
const lastAssistantMessageContent = response.choices[0].message.content;
|
|
191
|
+
try {
|
|
192
|
+
await memory.saveContext({ input: lastUserMessageContent }, { output: lastAssistantMessageContent });
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
console.error('Error saving messages to memory:', error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return outputData;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=message.operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.operation.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/message.operation.ts"],"names":[],"mappings":";;;;;AAqBA,0BAoTC;AAnUD,+CAA6D;AAE7D,uDAAgC;AACh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|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.router = router;
|
|
37
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
38
|
+
const messageOperation = __importStar(require("./message.operation"));
|
|
39
|
+
const errorHandling_1 = require("../helpers/api/errorHandling");
|
|
40
|
+
async function router(parentMessageContentStr = '', parentMessageContentObj = {}) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const returnData = [];
|
|
43
|
+
const items = this.getInputData();
|
|
44
|
+
let execute = messageOperation.execute;
|
|
45
|
+
for (let i = 0; i < items.length; i++) {
|
|
46
|
+
try {
|
|
47
|
+
const responseData = await execute.call(this, i, parentMessageContentStr, parentMessageContentObj);
|
|
48
|
+
returnData.push(...responseData);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (this.continueOnFail()) {
|
|
52
|
+
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (error instanceof n8n_workflow_1.NodeApiError) {
|
|
56
|
+
const errorCode = (_b = (_a = error.cause.error) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.code;
|
|
57
|
+
if (errorCode) {
|
|
58
|
+
const customErrorMessage = (0, errorHandling_1.getCustomErrorMessage)(errorCode);
|
|
59
|
+
if (customErrorMessage) {
|
|
60
|
+
error.message = customErrorMessage;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
error.context = {
|
|
64
|
+
itemIndex: i,
|
|
65
|
+
};
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
|
|
69
|
+
itemIndex: i,
|
|
70
|
+
description: error.description,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return [returnData];
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,wBAyCC;AAnDD,+CAKsB;AAEtB,sEAAuD;AACvD,gEAAqE;AAE9D,KAAK,UAAU,MAAM,CAA0B,0BAAkC,EAAE,EAAE,0BAAkC,EAAE;;IAE/H,MAAM,UAAU,GAAyB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