@n8n/n8n-nodes-langchain 1.112.2 → 1.113.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/dist/nodes/mcp/McpClientTool/McpClientTool.node.js +13 -18
- package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/descriptions.js +49 -0
- package/dist/nodes/mcp/McpClientTool/descriptions.js.map +1 -0
- package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js +24 -1
- package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js.map +1 -1
- package/dist/nodes/tools/ToolCode/ToolCode.node.js +122 -102
- package/dist/nodes/tools/ToolCode/ToolCode.node.js.map +1 -1
- package/dist/nodes/tools/ToolSearXng/ToolSearXng.node.js +29 -10
- package/dist/nodes/tools/ToolSearXng/ToolSearXng.node.js.map +1 -1
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js +22 -3
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js.map +1 -1
- package/dist/nodes/tools/ToolThink/ToolThink.node.js +32 -11
- package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +42 -21
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js +24 -3
- package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js.map +1 -1
- package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js +18 -0
- package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js +30 -13
- package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +27 -19
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/constants.js +2 -2
- package/dist/nodes/trigger/ChatTrigger/constants.js.map +1 -1
- package/dist/types/nodes.json +2 -2
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolSearXng/ToolSearXng.node.ts"],"sourcesContent":["import { SearxngSearch } from '@langchain/community/tools/searxng_search';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tINodeType,\n\tINodeTypeDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\ntype Options = {\n\tnumResults: number;\n\tpageNumber: number;\n\tlanguage: string;\n\tsafesearch: 0 | 1 | 2;\n};\n\nexport class ToolSearXng implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'SearXNG',\n\t\tname: 'toolSearXng',\n\t\ticon: 'file:searXng.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in SearXNG',\n\t\tdefaults: {\n\t\t\tname: 'SearXNG',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolsearxng',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'searXngApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Number of Results',\n\t\t\t\t\t\tname: 'numResults',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: 10,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Search Page Number',\n\t\t\t\t\t\tname: 'pageNumber',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Language',\n\t\t\t\t\t\tname: 'language',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'en',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the language to use. It\\'s a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French). Head to <a href=\"https://docs.searxng.org/user/search-syntax.html#select-language\">SearXNG search syntax page</a> for more info.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Safe Search',\n\t\t\t\t\t\tname: 'safesearch',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\t\t\tvalue: 0,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Moderate',\n\t\t\t\t\t\t\t\tvalue: 1,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Strict',\n\t\t\t\t\t\t\t\tvalue: 2,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 0,\n\t\t\t\t\t\tdescription: 'Filter search results of engines which support safe search',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolSearXng/ToolSearXng.node.ts"],"sourcesContent":["import { SearxngSearch } from '@langchain/community/tools/searxng_search';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\ntype Options = {\n\tnumResults: number;\n\tpageNumber: number;\n\tlanguage: string;\n\tsafesearch: 0 | 1 | 2;\n};\n\nasync function getTool(ctx: ISupplyDataFunctions | IExecuteFunctions, itemIndex: number) {\n\tconst credentials = await ctx.getCredentials<{ apiUrl: string }>('searXngApi');\n\tconst options = ctx.getNodeParameter('options', itemIndex) as Options;\n\n\treturn new SearxngSearch({\n\t\tapiBase: credentials.apiUrl,\n\t\theaders: {\n\t\t\tAccept: 'application/json',\n\t\t},\n\t\tparams: options,\n\t});\n}\n\nexport class ToolSearXng implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'SearXNG',\n\t\tname: 'toolSearXng',\n\t\ticon: 'file:searXng.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in SearXNG',\n\t\tdefaults: {\n\t\t\tname: 'SearXNG',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolsearxng',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'searXngApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Number of Results',\n\t\t\t\t\t\tname: 'numResults',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: 10,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Search Page Number',\n\t\t\t\t\t\tname: 'pageNumber',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Language',\n\t\t\t\t\t\tname: 'language',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'en',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the language to use. It\\'s a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French). Head to <a href=\"https://docs.searxng.org/user/search-syntax.html#select-language\">SearXNG search syntax page</a> for more info.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Safe Search',\n\t\t\t\t\t\tname: 'safesearch',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'None',\n\t\t\t\t\t\t\t\tvalue: 0,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Moderate',\n\t\t\t\t\t\t\t\tvalue: 1,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Strict',\n\t\t\t\t\t\t\t\tvalue: 2,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 0,\n\t\t\t\t\t\tdescription: 'Filter search results of engines which support safe search',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn {\n\t\t\tresponse: logWrapper(await getTool(this, itemIndex), this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst result: INodeExecutionData[] = [];\n\t\tconst input = this.getInputData();\n\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\tconst item = input[i];\n\t\t\tconst tool = await getTool(this, i);\n\t\t\tresult.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: await tool.invoke(item.json),\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: i,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [result];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA8B;AAC9B,0BAAoC;AAUpC,wBAA2B;AAC3B,0BAA6C;AAS7C,eAAe,QAAQ,KAA+C,WAAmB;AACxF,QAAM,cAAc,MAAM,IAAI,eAAmC,YAAY;AAC7E,QAAM,UAAU,IAAI,iBAAiB,WAAW,SAAS;AAEzD,SAAO,IAAI,oCAAc;AAAA,IACxB,SAAS,YAAY;AAAA,IACrB,SAAS;AAAA,MACR,QAAQ;AAAA,IACT;AA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AAM;AAAA,kBACN,OAAO;AAAA,gBACR;AAAA,gBACA;AAAA,kBACC,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR;AAAA,gBACA;AAAA,kBACC,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR;AAAA,cACD;AAAA,cACA,SAAS;AAAA,cACT,aAAa;AAAA,YACd;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,WAAO;AAAA,MACN,cAAU,8BAAW,MAAM,QAAQ,MAAM,SAAS,GAAG,IAAI;AAAA,IAC1D;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,SAA+B,CAAC;AACtC,UAAM,QAAQ,KAAK,aAAa;AAChC,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAM,OAAO,MAAM,CAAC;AACpB,YAAM,OAAO,MAAM,QAAQ,MAAM,CAAC;AAClC,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,UACL,UAAU,MAAM,KAAK,OAAO,KAAK,IAAI;AAAA,QACtC;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,MAAM;AAAA,EACf;AACD;","names":[]}
|
|
@@ -25,6 +25,11 @@ var import_serpapi = require("@langchain/community/tools/serpapi");
|
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
27
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
28
|
+
async function getTool(ctx, itemIndex) {
|
|
29
|
+
const credentials = await ctx.getCredentials("serpApi");
|
|
30
|
+
const options = ctx.getNodeParameter("options", itemIndex);
|
|
31
|
+
return new import_serpapi.SerpAPI(credentials.apiKey, options);
|
|
32
|
+
}
|
|
28
33
|
class ToolSerpApi {
|
|
29
34
|
constructor() {
|
|
30
35
|
this.description = {
|
|
@@ -124,12 +129,26 @@ class ToolSerpApi {
|
|
|
124
129
|
};
|
|
125
130
|
}
|
|
126
131
|
async supplyData(itemIndex) {
|
|
127
|
-
const credentials = await this.getCredentials("serpApi");
|
|
128
|
-
const options = this.getNodeParameter("options", itemIndex);
|
|
129
132
|
return {
|
|
130
|
-
response: (0, import_logWrapper.logWrapper)(
|
|
133
|
+
response: (0, import_logWrapper.logWrapper)(await getTool(this, itemIndex), this)
|
|
131
134
|
};
|
|
132
135
|
}
|
|
136
|
+
async execute() {
|
|
137
|
+
const inputData = this.getInputData();
|
|
138
|
+
const returnData = [];
|
|
139
|
+
for (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {
|
|
140
|
+
const tool = await getTool(this, itemIndex);
|
|
141
|
+
const query = inputData[itemIndex];
|
|
142
|
+
const result = await tool.invoke(query);
|
|
143
|
+
returnData.push({
|
|
144
|
+
json: {
|
|
145
|
+
response: result
|
|
146
|
+
},
|
|
147
|
+
pairedItem: { item: itemIndex }
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return [returnData];
|
|
151
|
+
}
|
|
133
152
|
}
|
|
134
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
135
154
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolSerpApi/ToolSerpApi.node.ts"],"sourcesContent":["import { SerpAPI } from '@langchain/community/tools/serpapi';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class ToolSerpApi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'SerpApi (Google Search)',\n\t\tname: 'toolSerpApi',\n\t\ticon: 'file:serpApi.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in Google using SerpAPI',\n\t\tdefaults: {\n\t\t\tname: 'SerpAPI',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolserpapi/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'serpApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Country',\n\t\t\t\t\t\tname: 'gl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'us',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the country to use for search. Head to <a href=\"https://serpapi.com/google-countries\">Google countries page</a> for a full list of supported countries.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Device',\n\t\t\t\t\t\tname: 'device',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Desktop',\n\t\t\t\t\t\t\t\tvalue: 'desktop',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Mobile',\n\t\t\t\t\t\t\t\tvalue: 'mobile',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Tablet',\n\t\t\t\t\t\t\t\tvalue: 'tablet',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'desktop',\n\t\t\t\t\t\tdescription: 'Device to use to get the results',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Explicit Array',\n\t\t\t\t\t\tname: 'no_cache',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to force SerpApi to fetch the Google results even if a cached version is already present. Cache expires after 1h. Cached searches are free, and are not counted towards your searches per month.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Google Domain',\n\t\t\t\t\t\tname: 'google_domain',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'google.com',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the domain to use for search. Head to <a href=\"https://serpapi.com/google-domains\">Google domains page</a> for a full list of supported domains.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Language',\n\t\t\t\t\t\tname: 'hl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'en',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the language to use. It\\'s a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French). Head to <a href=\"https://serpapi.com/google-languages\">Google languages page</a> for a full list of supported languages.',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolSerpApi/ToolSerpApi.node.ts"],"sourcesContent":["import { SerpAPI } from '@langchain/community/tools/serpapi';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\nasync function getTool(ctx: ISupplyDataFunctions | IExecuteFunctions, itemIndex: number) {\n\tconst credentials = await ctx.getCredentials('serpApi');\n\n\tconst options = ctx.getNodeParameter('options', itemIndex) as object;\n\n\treturn new SerpAPI(credentials.apiKey as string, options);\n}\n\nexport class ToolSerpApi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'SerpApi (Google Search)',\n\t\tname: 'toolSerpApi',\n\t\ticon: 'file:serpApi.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in Google using SerpAPI',\n\t\tdefaults: {\n\t\t\tname: 'SerpAPI',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolserpapi/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'serpApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Country',\n\t\t\t\t\t\tname: 'gl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'us',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the country to use for search. Head to <a href=\"https://serpapi.com/google-countries\">Google countries page</a> for a full list of supported countries.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Device',\n\t\t\t\t\t\tname: 'device',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Desktop',\n\t\t\t\t\t\t\t\tvalue: 'desktop',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Mobile',\n\t\t\t\t\t\t\t\tvalue: 'mobile',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Tablet',\n\t\t\t\t\t\t\t\tvalue: 'tablet',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'desktop',\n\t\t\t\t\t\tdescription: 'Device to use to get the results',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Explicit Array',\n\t\t\t\t\t\tname: 'no_cache',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to force SerpApi to fetch the Google results even if a cached version is already present. Cache expires after 1h. Cached searches are free, and are not counted towards your searches per month.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Google Domain',\n\t\t\t\t\t\tname: 'google_domain',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'google.com',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the domain to use for search. Head to <a href=\"https://serpapi.com/google-domains\">Google domains page</a> for a full list of supported domains.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Language',\n\t\t\t\t\t\tname: 'hl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'en',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the language to use. It\\'s a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French). Head to <a href=\"https://serpapi.com/google-languages\">Google languages page</a> for a full list of supported languages.',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn {\n\t\t\tresponse: logWrapper(await getTool(this, itemIndex), this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst inputData = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {\n\t\t\tconst tool = await getTool(this, itemIndex);\n\t\t\tconst query = inputData[itemIndex];\n\t\t\tconst result = await tool.invoke(query);\n\t\t\treturnData.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: result,\n\t\t\t\t},\n\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t});\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AACxB,0BAQO;AAEP,wBAA2B;AAC3B,0BAA6C;AAC7C,eAAe,QAAQ,KAA+C,WAAmB;AACxF,QAAM,cAAc,MAAM,IAAI,eAAe,SAAS;AAEtD,QAAM,UAAU,IAAI,iBAAiB,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gBACR;AAAA,cACD;AAAA,cACA,SAAS;AAAA,cACT,aAAa;AAAA,YACd;AAAA,YACA;AAAA,cACC,aAAa;AAAA,cACb,MAAM;AAAA,cACN,MAAM;AAAA,cACN,SAAS;AAAA,cACT,aACC;AAAA,YACF;AAAA,YACA;AAAA,cACC,aAAa;AAAA,cACb,MAAM;AAAA,cACN,MAAM;AAAA,cACN,SAAS;AAAA,cACT,aACC;AAAA,YACF;AAAA,YACA;AAAA,cACC,aAAa;AAAA,cACb,MAAM;AAAA,cACN,MAAM;AAAA,cACN,SAAS;AAAA,cACT,aACC;AAAA,YACF;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,WAAO;AAAA,MACN,cAAU,8BAAW,MAAM,QAAQ,MAAM,SAAS,GAAG,IAAI;AAAA,IAC1D;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,YAAY,KAAK,aAAa;AACpC,UAAM,aAAmC,CAAC;AAC1C,aAAS,YAAY,GAAG,YAAY,UAAU,QAAQ,aAAa;AAClE,YAAM,OAAO,MAAM,QAAQ,MAAM,SAAS;AAC1C,YAAM,QAAQ,UAAU,SAAS;AACjC,YAAM,SAAS,MAAM,KAAK,OAAO,KAAK;AACtC,iBAAW,KAAK;AAAA,QACf,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY,EAAE,MAAM,UAAU;AAAA,MAC/B,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -25,6 +25,19 @@ var import_tools = require("langchain/tools");
|
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
27
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
28
|
+
async function getTool(ctx, itemIndex) {
|
|
29
|
+
const node = ctx.getNode();
|
|
30
|
+
const { typeVersion } = node;
|
|
31
|
+
const name = typeVersion === 1 ? "thinking_tool" : (0, import_n8n_workflow.nodeNameToToolName)(node);
|
|
32
|
+
const description = ctx.getNodeParameter("description", itemIndex);
|
|
33
|
+
return new import_tools.DynamicTool({
|
|
34
|
+
name,
|
|
35
|
+
description,
|
|
36
|
+
func: async (subject) => {
|
|
37
|
+
return subject;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
28
41
|
const defaultToolDescription = "Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.";
|
|
29
42
|
class ToolThink {
|
|
30
43
|
constructor() {
|
|
@@ -74,21 +87,29 @@ class ToolThink {
|
|
|
74
87
|
};
|
|
75
88
|
}
|
|
76
89
|
async supplyData(itemIndex) {
|
|
77
|
-
const
|
|
78
|
-
const { typeVersion } = node;
|
|
79
|
-
const name = typeVersion === 1 ? "thinking_tool" : (0, import_n8n_workflow.nodeNameToToolName)(node);
|
|
80
|
-
const description = this.getNodeParameter("description", itemIndex);
|
|
81
|
-
const tool = new import_tools.DynamicTool({
|
|
82
|
-
name,
|
|
83
|
-
description,
|
|
84
|
-
func: async (subject) => {
|
|
85
|
-
return subject;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
90
|
+
const tool = await getTool(this, itemIndex);
|
|
88
91
|
return {
|
|
89
92
|
response: (0, import_logWrapper.logWrapper)(tool, this)
|
|
90
93
|
};
|
|
91
94
|
}
|
|
95
|
+
async execute() {
|
|
96
|
+
const input = this.getInputData();
|
|
97
|
+
const response = [];
|
|
98
|
+
for (let i = 0; i < input.length; i++) {
|
|
99
|
+
const inputItem = input[i];
|
|
100
|
+
const tool = await getTool(this, i);
|
|
101
|
+
const result = await tool.invoke(inputItem.json);
|
|
102
|
+
response.push({
|
|
103
|
+
json: {
|
|
104
|
+
response: result
|
|
105
|
+
},
|
|
106
|
+
pairedItem: {
|
|
107
|
+
item: i
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return [response];
|
|
112
|
+
}
|
|
92
113
|
}
|
|
93
114
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
115
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolThink/ToolThink.node.ts"],"sourcesContent":["import { DynamicTool } from 'langchain/tools';\nimport {\n\tNodeConnectionTypes,\n\tnodeNameToToolName,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\n// A thinking tool, see https://www.anthropic.com/engineering/claude-think-tool\n\nconst defaultToolDescription =\n\t'Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.';\n\nexport class ToolThink implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Think Tool',\n\t\tname: 'toolThink',\n\t\ticon: 'fa:brain',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Invite the AI agent to do some thinking',\n\t\tdefaults: {\n\t\t\tname: 'Think',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolthink/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Think Tool Description',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: defaultToolDescription,\n\t\t\t\tplaceholder: '[Describe your thinking tool here, explaining how it will help the AI think]',\n\t\t\t\tdescription: \"The thinking tool's description\",\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolThink/ToolThink.node.ts"],"sourcesContent":["import { DynamicTool } from 'langchain/tools';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\tnodeNameToToolName,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): Promise<DynamicTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\n\tconst name = typeVersion === 1 ? 'thinking_tool' : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', itemIndex) as string;\n\n\treturn new DynamicTool({\n\t\tname,\n\t\tdescription,\n\t\tfunc: async (subject: string) => {\n\t\t\treturn subject;\n\t\t},\n\t});\n}\n\n// A thinking tool, see https://www.anthropic.com/engineering/claude-think-tool\n\nconst defaultToolDescription =\n\t'Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.';\n\nexport class ToolThink implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Think Tool',\n\t\tname: 'toolThink',\n\t\ticon: 'fa:brain',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Invite the AI agent to do some thinking',\n\t\tdefaults: {\n\t\t\tname: 'Think',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolthink/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Think Tool Description',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: defaultToolDescription,\n\t\t\t\tplaceholder: '[Describe your thinking tool here, explaining how it will help the AI think]',\n\t\t\t\tdescription: \"The thinking tool's description\",\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst tool = await getTool(this, itemIndex);\n\n\t\treturn {\n\t\t\tresponse: logWrapper(tool, this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst input = this.getInputData();\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\tconst inputItem = input[i];\n\t\t\tconst tool = await getTool(this, i);\n\t\t\tconst result = await tool.invoke(inputItem.json);\n\t\t\tresponse.push({\n\t\t\t\tjson: {\n\t\t\t\t\tres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,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,UACb,aAAa;AAAA,UACb,aAAa;AAAA,YACZ,MAAM;AAAA,UACP;AAAA,UACA,UAAU;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,MAAM,QAAQ,MAAM,SAAS;AAE1C,WAAO;AAAA,MACN,cAAU,8BAAW,MAAM,IAAI;AAAA,IAChC;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,QAAQ,KAAK,aAAa;AAChC,UAAM,WAAiC,CAAC;AACxC,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAM,YAAY,MAAM,CAAC;AACzB,YAAM,OAAO,MAAM,QAAQ,MAAM,CAAC;AAClC,YAAM,SAAS,MAAM,KAAK,OAAO,UAAU,IAAI;AAC/C,eAAS,KAAK;AAAA,QACb,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
|
|
@@ -26,6 +26,30 @@ var import_tools = require("langchain/tools");
|
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
28
28
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
29
|
+
async function getTool(ctx, itemIndex) {
|
|
30
|
+
const node = ctx.getNode();
|
|
31
|
+
const { typeVersion } = node;
|
|
32
|
+
const name = typeVersion <= 1 ? ctx.getNodeParameter("name", itemIndex) : (0, import_n8n_workflow.nodeNameToToolName)(node);
|
|
33
|
+
const toolDescription = ctx.getNodeParameter("description", itemIndex);
|
|
34
|
+
const topK = ctx.getNodeParameter("topK", itemIndex, 4);
|
|
35
|
+
const description = import_tools.VectorStoreQATool.getDescription(name, toolDescription);
|
|
36
|
+
const vectorStore = await ctx.getInputConnectionData(
|
|
37
|
+
import_n8n_workflow.NodeConnectionTypes.AiVectorStore,
|
|
38
|
+
itemIndex
|
|
39
|
+
);
|
|
40
|
+
const llm = await ctx.getInputConnectionData(
|
|
41
|
+
import_n8n_workflow.NodeConnectionTypes.AiLanguageModel,
|
|
42
|
+
itemIndex
|
|
43
|
+
);
|
|
44
|
+
const vectorStoreTool = new import_tools.VectorStoreQATool(name, description, {
|
|
45
|
+
llm,
|
|
46
|
+
vectorStore
|
|
47
|
+
});
|
|
48
|
+
vectorStoreTool.chain = import_chains.VectorDBQAChain.fromLLM(llm, vectorStore, {
|
|
49
|
+
k: topK
|
|
50
|
+
});
|
|
51
|
+
return vectorStoreTool;
|
|
52
|
+
}
|
|
29
53
|
class ToolVectorStore {
|
|
30
54
|
constructor() {
|
|
31
55
|
this.description = {
|
|
@@ -107,31 +131,28 @@ class ToolVectorStore {
|
|
|
107
131
|
};
|
|
108
132
|
}
|
|
109
133
|
async supplyData(itemIndex) {
|
|
110
|
-
const
|
|
111
|
-
const { typeVersion } = node;
|
|
112
|
-
const name = typeVersion <= 1 ? this.getNodeParameter("name", itemIndex) : (0, import_n8n_workflow.nodeNameToToolName)(node);
|
|
113
|
-
const toolDescription = this.getNodeParameter("description", itemIndex);
|
|
114
|
-
const topK = this.getNodeParameter("topK", itemIndex, 4);
|
|
115
|
-
const vectorStore = await this.getInputConnectionData(
|
|
116
|
-
import_n8n_workflow.NodeConnectionTypes.AiVectorStore,
|
|
117
|
-
itemIndex
|
|
118
|
-
);
|
|
119
|
-
const llm = await this.getInputConnectionData(
|
|
120
|
-
import_n8n_workflow.NodeConnectionTypes.AiLanguageModel,
|
|
121
|
-
0
|
|
122
|
-
);
|
|
123
|
-
const description = import_tools.VectorStoreQATool.getDescription(name, toolDescription);
|
|
124
|
-
const vectorStoreTool = new import_tools.VectorStoreQATool(name, description, {
|
|
125
|
-
llm,
|
|
126
|
-
vectorStore
|
|
127
|
-
});
|
|
128
|
-
vectorStoreTool.chain = import_chains.VectorDBQAChain.fromLLM(llm, vectorStore, {
|
|
129
|
-
k: topK
|
|
130
|
-
});
|
|
134
|
+
const vectorStoreTool = await getTool(this, itemIndex);
|
|
131
135
|
return {
|
|
132
136
|
response: (0, import_logWrapper.logWrapper)(vectorStoreTool, this)
|
|
133
137
|
};
|
|
134
138
|
}
|
|
139
|
+
async execute() {
|
|
140
|
+
const inputData = this.getInputData();
|
|
141
|
+
const result = [];
|
|
142
|
+
for (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {
|
|
143
|
+
const tool = await getTool(this, itemIndex);
|
|
144
|
+
const outputData = await tool.invoke(inputData[itemIndex].json);
|
|
145
|
+
result.push({
|
|
146
|
+
json: {
|
|
147
|
+
response: outputData
|
|
148
|
+
},
|
|
149
|
+
pairedItem: {
|
|
150
|
+
item: itemIndex
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return [result];
|
|
155
|
+
}
|
|
135
156
|
}
|
|
136
157
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
158
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolVectorStore/ToolVectorStore.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { VectorDBQAChain } from 'langchain/chains';\nimport { VectorStoreQATool } from 'langchain/tools';\nimport type {\n\tINodeType,\n\tINodeTypeDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, nodeNameToToolName } from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class ToolVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Question Answer Tool',\n\t\tname: 'toolVectorStore',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Answer questions with a vector store',\n\t\tdefaults: {\n\t\t\tname: 'Answer questions with a vector store',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolvectorstore/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Data Name',\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. users_info',\n\t\t\t\tvalidateType: 'string-alphanumeric',\n\t\t\t\tdescription:\n\t\t\t\t\t'Name of the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Description of Data',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: \"[Describe your data here, e.g. a user's name, email, etc.]\",\n\t\t\t\tdescription:\n\t\t\t\t\t'Describe the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolVectorStore/ToolVectorStore.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { VectorDBQAChain } from 'langchain/chains';\nimport { VectorStoreQATool } from 'langchain/tools';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, nodeNameToToolName } from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): Promise<VectorStoreQATool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst name =\n\t\ttypeVersion <= 1\n\t\t\t? (ctx.getNodeParameter('name', itemIndex) as string)\n\t\t\t: nodeNameToToolName(node);\n\tconst toolDescription = ctx.getNodeParameter('description', itemIndex) as string;\n\tconst topK = ctx.getNodeParameter('topK', itemIndex, 4) as number;\n\tconst description = VectorStoreQATool.getDescription(name, toolDescription);\n\tconst vectorStore = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiVectorStore,\n\t\titemIndex,\n\t)) as VectorStore;\n\tconst llm = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\titemIndex,\n\t)) as BaseLanguageModel;\n\n\tconst vectorStoreTool = new VectorStoreQATool(name, description, {\n\t\tllm,\n\t\tvectorStore,\n\t});\n\n\tvectorStoreTool.chain = VectorDBQAChain.fromLLM(llm, vectorStore, {\n\t\tk: topK,\n\t});\n\n\treturn vectorStoreTool;\n}\n\nexport class ToolVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Question Answer Tool',\n\t\tname: 'toolVectorStore',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Answer questions with a vector store',\n\t\tdefaults: {\n\t\t\tname: 'Answer questions with a vector store',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolvectorstore/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Data Name',\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. users_info',\n\t\t\t\tvalidateType: 'string-alphanumeric',\n\t\t\t\tdescription:\n\t\t\t\t\t'Name of the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Description of Data',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: \"[Describe your data here, e.g. a user's name, email, etc.]\",\n\t\t\t\tdescription:\n\t\t\t\t\t'Describe the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst vectorStoreTool = await getTool(this, itemIndex);\n\n\t\treturn {\n\t\t\tresponse: logWrapper(vectorStoreTool, this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst inputData = this.getInputData();\n\t\tconst result: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {\n\t\t\tconst tool = await getTool(this, itemIndex);\n\t\t\tconst outputData = await tool.invoke(inputData[itemIndex].json);\n\t\t\tresult.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: outputData,\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: itemIndex,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [result];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAgC;AAChC,mBAAkC;AASlC,0BAAwD;AAExD,wBAA2B;AAC3B,0BAA6C;AAE7C,eAAe,QACd,KACA,WAC6B;AAC7B,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,OACL,eAAe,IACX,IAAI,iBAAiB,QAAQ,SAAS,QACvC,wCAAmB,IAAI;AAC3B,QAAM,kBAAkB,IAAI,iBAAiB,eAAe,SAAS;AACrE,QAAM,OAAO,IAAI,iBAAiB,QAAQ,WAAW,CAAC;AACtD,QAAM,cAAc,+BAAkB,eAAe,MAAM,eAAe;AAC1E,QAAM,cAAe,MAAM,IAAI;AAAA,IAC9B,wCAAoB;AAAA,IACpB;AAAA,EACD;AACA,QAAM,MAAO,MAAM,IAAI;AAAA,IACtB,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,QAAM,kBAAkB,IAAI,+BAAkB,MAAM,aAAa;AAAA,IAChE;AAAA,IACA;AAAA,EACD,CAAC;AAED,kBAAgB,QAAQ,8BAAgB,QAAQ,KAAK,aAAa;AAAA,IACjE,GAAG;AAAA,EACJ,CAAC;AAED,SAAO;AACR;AAEO,MAAM,gBAAqC;AAAA,EAA3C;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,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,QACd;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,kBAAkB,MAAM,QAAQ,MAAM,SAAS;AAErD,WAAO;AAAA,MACN,cAAU,8BAAW,iBAAiB,IAAI;AAAA,IAC3C;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,YAAY,KAAK,aAAa;AACpC,UAAM,SAA+B,CAAC;AACtC,aAAS,YAAY,GAAG,YAAY,UAAU,QAAQ,aAAa;AAClE,YAAM,OAAO,MAAM,QAAQ,MAAM,SAAS;AAC1C,YAAM,aAAa,MAAM,KAAK,OAAO,UAAU,SAAS,EAAE,IAAI;AAC9D,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,MAAM;AAAA,EACf;AACD;","names":[]}
|
|
@@ -25,6 +25,12 @@ var import_wikipedia_query_run = require("@langchain/community/tools/wikipedia_q
|
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
27
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
28
|
+
function getTool(ctx) {
|
|
29
|
+
const WikiTool = new import_wikipedia_query_run.WikipediaQueryRun();
|
|
30
|
+
WikiTool.name = ctx.getNode().name;
|
|
31
|
+
WikiTool.description = "A tool for interacting with and fetching data from the Wikipedia API. The input should always be a string query.";
|
|
32
|
+
return WikiTool;
|
|
33
|
+
}
|
|
28
34
|
class ToolWikipedia {
|
|
29
35
|
constructor() {
|
|
30
36
|
this.description = {
|
|
@@ -58,12 +64,27 @@ class ToolWikipedia {
|
|
|
58
64
|
};
|
|
59
65
|
}
|
|
60
66
|
async supplyData() {
|
|
61
|
-
const WikiTool = new import_wikipedia_query_run.WikipediaQueryRun();
|
|
62
|
-
WikiTool.description = "A tool for interacting with and fetching data from the Wikipedia API. The input should always be a string query.";
|
|
63
67
|
return {
|
|
64
|
-
response: (0, import_logWrapper.logWrapper)(
|
|
68
|
+
response: (0, import_logWrapper.logWrapper)(getTool(this), this)
|
|
65
69
|
};
|
|
66
70
|
}
|
|
71
|
+
async execute() {
|
|
72
|
+
const WikiTool = getTool(this);
|
|
73
|
+
const items = this.getInputData();
|
|
74
|
+
const response = [];
|
|
75
|
+
for (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {
|
|
76
|
+
const item = items[itemIndex];
|
|
77
|
+
if (item === void 0) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const result = await WikiTool.invoke(item.json);
|
|
81
|
+
response.push({
|
|
82
|
+
json: { response: result },
|
|
83
|
+
pairedItem: { item: itemIndex }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return [response];
|
|
87
|
+
}
|
|
67
88
|
}
|
|
68
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
90
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolWikipedia/ToolWikipedia.node.ts"],"sourcesContent":["import { WikipediaQueryRun } from '@langchain/community/tools/wikipedia_query_run';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class ToolWikipedia implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Wikipedia',\n\t\tname: 'toolWikipedia',\n\t\ticon: 'file:wikipedia.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in Wikipedia',\n\t\tdefaults: {\n\t\t\tname: 'Wikipedia',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolwikipedia/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [getConnectionHintNoticeField([NodeConnectionTypes.AiAgent])],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions): Promise<SupplyData> {\n\t\tconst WikiTool =
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolWikipedia/ToolWikipedia.node.ts"],"sourcesContent":["import { WikipediaQueryRun } from '@langchain/community/tools/wikipedia_query_run';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nfunction getTool(ctx: ISupplyDataFunctions | IExecuteFunctions): WikipediaQueryRun {\n\tconst WikiTool = new WikipediaQueryRun();\n\tWikiTool.name = ctx.getNode().name;\n\tWikiTool.description =\n\t\t'A tool for interacting with and fetching data from the Wikipedia API. The input should always be a string query.';\n\treturn WikiTool;\n}\n\nexport class ToolWikipedia implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Wikipedia',\n\t\tname: 'toolWikipedia',\n\t\ticon: 'file:wikipedia.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in Wikipedia',\n\t\tdefaults: {\n\t\t\tname: 'Wikipedia',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolwikipedia/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [getConnectionHintNoticeField([NodeConnectionTypes.AiAgent])],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions): Promise<SupplyData> {\n\t\treturn {\n\t\t\tresponse: logWrapper(getTool(this), this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst WikiTool = getTool(this);\n\n\t\tconst items = this.getInputData();\n\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tif (item === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = await WikiTool.invoke(item.json);\n\t\t\tresponse.push({\n\t\t\t\tjson: { response: result },\n\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t});\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAkC;AAClC,0BAQO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,SAAS,QAAQ,KAAkE;AAClF,QAAM,WAAW,IAAI,6CAAkB;AACvC,WAAS,OAAO,IAAI,QAAQ,EAAE;AAC9B,WAAS,cACR;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+69,24 @@ class ToolWolframAlpha {
|
|
|
69
69
|
response: (0, import_logWrapper.logWrapper)(new import_wolframalpha.WolframAlphaTool({ appid: credentials.appId }), this)
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
+
async execute() {
|
|
73
|
+
const credentials = await this.getCredentials("wolframAlphaApi");
|
|
74
|
+
const input = this.getInputData();
|
|
75
|
+
const result = [];
|
|
76
|
+
for (let i = 0; i < input.length; i++) {
|
|
77
|
+
const item = input[i];
|
|
78
|
+
const tool = new import_wolframalpha.WolframAlphaTool({ appid: credentials.appId });
|
|
79
|
+
result.push({
|
|
80
|
+
json: {
|
|
81
|
+
response: await tool.invoke(item.json)
|
|
82
|
+
},
|
|
83
|
+
pairedItem: {
|
|
84
|
+
item: i
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return [result];
|
|
89
|
+
}
|
|
72
90
|
}
|
|
73
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
92
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts"],"sourcesContent":["import { WolframAlphaTool } from '@langchain/community/tools/wolframalpha';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class ToolWolframAlpha implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Wolfram|Alpha',\n\t\tname: 'toolWolframAlpha',\n\t\ticon: 'file:wolfram-alpha.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: \"Connects to WolframAlpha's computational intelligence engine.\",\n\t\tdefaults: {\n\t\t\tname: 'Wolfram Alpha',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'wolframAlphaApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolwolframalpha/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [getConnectionHintNoticeField([NodeConnectionTypes.AiAgent])],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('wolframAlphaApi');\n\n\t\treturn {\n\t\t\tresponse: logWrapper(new WolframAlphaTool({ appid: credentials.appId as string }), this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAiC;AACjC,
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.ts"],"sourcesContent":["import { WolframAlphaTool } from '@langchain/community/tools/wolframalpha';\nimport {\n\tNodeConnectionTypes,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class ToolWolframAlpha implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Wolfram|Alpha',\n\t\tname: 'toolWolframAlpha',\n\t\ticon: 'file:wolfram-alpha.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: \"Connects to WolframAlpha's computational intelligence engine.\",\n\t\tdefaults: {\n\t\t\tname: 'Wolfram Alpha',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'wolframAlphaApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolwolframalpha/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [getConnectionHintNoticeField([NodeConnectionTypes.AiAgent])],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('wolframAlphaApi');\n\n\t\treturn {\n\t\t\tresponse: logWrapper(new WolframAlphaTool({ appid: credentials.appId as string }), this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst credentials = await this.getCredentials('wolframAlphaApi');\n\t\tconst input = this.getInputData();\n\t\tconst result: INodeExecutionData[] = [];\n\n\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\tconst item = input[i];\n\t\t\tconst tool = new WolframAlphaTool({ appid: credentials.appId as string });\n\t\t\tresult.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: await tool.invoke(item.json),\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: i,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [result];\n\t}\n}\n"],"mappings":";;;;;;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,qCAAiB,EAAE,OAAO,YAAY,MAAgB,CAAC;AACxE,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,UACL,UAAU,MAAM,KAAK,OAAO,KAAK,IAAI;AAAA,QACtC;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,MAAM;AAAA,EACf;AACD;","names":[]}
|
|
@@ -25,6 +25,21 @@ var import_n8n_workflow = require("n8n-workflow");
|
|
|
25
25
|
var import_methods = require("./methods");
|
|
26
26
|
var import_WorkflowToolService = require("./utils/WorkflowToolService");
|
|
27
27
|
var import_versionDescription = require("./versionDescription");
|
|
28
|
+
async function getTool(ctx, enableLogging, itemIndex) {
|
|
29
|
+
const node = ctx.getNode();
|
|
30
|
+
const { typeVersion } = node;
|
|
31
|
+
const returnAllItems = typeVersion > 2;
|
|
32
|
+
const workflowToolService = new import_WorkflowToolService.WorkflowToolService(ctx, { returnAllItems });
|
|
33
|
+
const name = typeVersion <= 2.1 ? ctx.getNodeParameter("name", 0) : (0, import_n8n_workflow.nodeNameToToolName)(node);
|
|
34
|
+
const description = ctx.getNodeParameter("description", 0);
|
|
35
|
+
return await workflowToolService.createTool({
|
|
36
|
+
ctx,
|
|
37
|
+
name,
|
|
38
|
+
description,
|
|
39
|
+
itemIndex,
|
|
40
|
+
manualLogging: enableLogging
|
|
41
|
+
});
|
|
42
|
+
}
|
|
28
43
|
class ToolWorkflowV2 {
|
|
29
44
|
constructor(baseDescription) {
|
|
30
45
|
this.methods = {
|
|
@@ -36,19 +51,21 @@ class ToolWorkflowV2 {
|
|
|
36
51
|
};
|
|
37
52
|
}
|
|
38
53
|
async supplyData(itemIndex) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
return { response: await getTool(this, true, itemIndex) };
|
|
55
|
+
}
|
|
56
|
+
async execute() {
|
|
57
|
+
const items = this.getInputData();
|
|
58
|
+
const response = [];
|
|
59
|
+
for (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {
|
|
60
|
+
const item = items[itemIndex];
|
|
61
|
+
const tool = await getTool(this, false, itemIndex);
|
|
62
|
+
if (item === void 0) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const result = await tool.invoke(item.json);
|
|
66
|
+
response.push(result);
|
|
67
|
+
}
|
|
68
|
+
return [response];
|
|
52
69
|
}
|
|
53
70
|
}
|
|
54
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts"],"sourcesContent":["import type {\n\tINodeTypeBaseDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts"],"sourcesContent":["import type { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\n\nimport type {\n\tINodeTypeBaseDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n\tINodeType,\n\tINodeTypeDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n} from 'n8n-workflow';\nimport { nodeNameToToolName } from 'n8n-workflow';\n\nimport { localResourceMapping } from './methods';\nimport { WorkflowToolService } from './utils/WorkflowToolService';\nimport { versionDescription } from './versionDescription';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tenableLogging: boolean,\n\titemIndex: number,\n): Promise<DynamicTool | DynamicStructuredTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst returnAllItems = typeVersion > 2;\n\n\tconst workflowToolService = new WorkflowToolService(ctx, { returnAllItems });\n\tconst name =\n\t\ttypeVersion <= 2.1 ? (ctx.getNodeParameter('name', 0) as string) : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', 0) as string;\n\n\treturn await workflowToolService.createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t\tmanualLogging: enableLogging,\n\t});\n}\n\nexport class ToolWorkflowV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\t...versionDescription,\n\t\t};\n\t}\n\n\tmethods = {\n\t\tlocalResourceMapping,\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn { response: await getTool(this, true, itemIndex) };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst items = this.getInputData();\n\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst tool = await getTool(this, false, itemIndex);\n\n\t\t\tif (item === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = await tool.invoke(item.json);\n\t\t\tresponse.push(result);\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,0BAAmC;AAEnC,qBAAqC;AACrC,iCAAoC;AACpC,gCAAmC;AAEnC,eAAe,QACd,KACA,eACA,WAC+C;AAC/C,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,iBAAiB,cAAc;AAErC,QAAM,sBAAsB,IAAI,+CAAoB,KAAK,EAAE,eAAe,CAAC;AAC3E,QAAM,OACL,eAAe,MAAO,IAAI,iBAAiB,QAAQ,CAAC,QAAe,wCAAmB,IAAI;AAC3F,QAAM,cAAc,IAAI,iBAAiB,eAAe,CAAC;AAEzD,SAAO,MAAM,oBAAoB,WAAW;AAAA,IAC3C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,EAChB,CAAC;AACF;AAEO,MAAM,eAAoC;AAAA,EAGhD,YAAY,iBAA2C;AAOvD,mBAAU;AAAA,MACT;AAAA,IACD;AARC,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,WAAO,EAAE,UAAU,MAAM,QAAQ,MAAM,MAAM,SAAS,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,QAAQ,KAAK,aAAa;AAEhC,UAAM,WAAiC,CAAC;AACxC,aAAS,YAAY,GAAG,YAAY,KAAK,aAAa,EAAE,QAAQ,aAAa;AAC5E,YAAM,OAAO,MAAM,SAAS;AAC5B,YAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,SAAS;AAEjD,UAAI,SAAS,QAAW;AACvB;AAAA,MACD;AACA,YAAM,SAAS,MAAM,KAAK,OAAO,KAAK,IAAI;AAC1C,eAAS,KAAK,MAAM;AAAA,IACrB;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
|
|
@@ -54,10 +54,11 @@ class WorkflowToolService {
|
|
|
54
54
|
ctx,
|
|
55
55
|
name,
|
|
56
56
|
description,
|
|
57
|
-
itemIndex
|
|
57
|
+
itemIndex,
|
|
58
|
+
manualLogging = true
|
|
58
59
|
}) {
|
|
59
60
|
const node = ctx.getNode();
|
|
60
|
-
let runIndex = ctx.getNextRunIndex();
|
|
61
|
+
let runIndex = "getNextRunIndex" in ctx ? ctx.getNextRunIndex() : 0;
|
|
61
62
|
const toolHandler = async (query, runManager) => {
|
|
62
63
|
let maxTries = 1;
|
|
63
64
|
if (node.retryOnFail === true) {
|
|
@@ -70,10 +71,13 @@ class WorkflowToolService {
|
|
|
70
71
|
let lastError;
|
|
71
72
|
for (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {
|
|
72
73
|
const localRunIndex = runIndex++;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
let context = this.baseContext;
|
|
75
|
+
if ("cloneWith" in this.baseContext) {
|
|
76
|
+
context = this.baseContext.cloneWith({
|
|
77
|
+
runIndex: localRunIndex,
|
|
78
|
+
inputData: [[{ json: { query } }]]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
77
81
|
const abortSignal = context.getExecutionCancelSignal?.();
|
|
78
82
|
if (abortSignal?.aborted) {
|
|
79
83
|
return 'There was an error: "Execution was cancelled"';
|
|
@@ -109,12 +113,14 @@ class WorkflowToolService {
|
|
|
109
113
|
}
|
|
110
114
|
};
|
|
111
115
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
if (manualLogging) {
|
|
117
|
+
void context.addOutputData(
|
|
118
|
+
import_n8n_workflow.NodeConnectionTypes.AiTool,
|
|
119
|
+
localRunIndex,
|
|
120
|
+
[responseData],
|
|
121
|
+
metadata
|
|
122
|
+
);
|
|
123
|
+
}
|
|
118
124
|
return processedResponse;
|
|
119
125
|
} catch (error) {
|
|
120
126
|
if (abortSignal?.aborted) {
|
|
@@ -123,13 +129,15 @@ class WorkflowToolService {
|
|
|
123
129
|
const executionError = error;
|
|
124
130
|
lastError = executionError;
|
|
125
131
|
const errorResponse = `There was an error: "${executionError.message}"`;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
if (manualLogging) {
|
|
133
|
+
const metadata = (0, import_n8n_workflow.parseErrorMetadata)(error);
|
|
134
|
+
void context.addOutputData(
|
|
135
|
+
import_n8n_workflow.NodeConnectionTypes.AiTool,
|
|
136
|
+
localRunIndex,
|
|
137
|
+
executionError,
|
|
138
|
+
metadata
|
|
139
|
+
);
|
|
140
|
+
}
|
|
133
141
|
if (tryIndex === maxTries - 1) {
|
|
134
142
|
return errorResponse;
|
|
135
143
|
}
|