@n8n/ai-utilities 0.16.1 → 0.17.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/cjs/node-catalog/discriminator-utils.d.ts +22 -0
- package/dist/cjs/node-catalog/discriminator-utils.js +95 -0
- package/dist/cjs/node-catalog/discriminator-utils.js.map +1 -0
- package/dist/cjs/node-catalog/get.d.ts +18 -0
- package/dist/cjs/node-catalog/get.js +368 -0
- package/dist/cjs/node-catalog/get.js.map +1 -0
- package/dist/cjs/node-catalog/index.d.ts +14 -0
- package/dist/cjs/node-catalog/index.js +40 -0
- package/dist/cjs/node-catalog/index.js.map +1 -0
- package/dist/cjs/node-catalog/lean-node-type.d.ts +27 -0
- package/dist/cjs/node-catalog/lean-node-type.js +60 -0
- package/dist/cjs/node-catalog/lean-node-type.js.map +1 -0
- package/dist/cjs/node-catalog/node-type-parser.d.ts +20 -0
- package/dist/cjs/node-catalog/node-type-parser.js +79 -0
- package/dist/cjs/node-catalog/node-type-parser.js.map +1 -0
- package/dist/cjs/node-catalog/resource-operation-extractor.d.ts +26 -0
- package/dist/cjs/node-catalog/resource-operation-extractor.js +166 -0
- package/dist/cjs/node-catalog/resource-operation-extractor.js.map +1 -0
- package/dist/cjs/node-catalog/search-engine.d.ts +20 -0
- package/dist/cjs/node-catalog/search-engine.js +257 -0
- package/dist/cjs/node-catalog/search-engine.js.map +1 -0
- package/dist/cjs/node-catalog/search.d.ts +10 -0
- package/dist/cjs/node-catalog/search.js +331 -0
- package/dist/cjs/node-catalog/search.js.map +1 -0
- package/dist/cjs/node-catalog/suggested-nodes-data.d.ts +11 -0
- package/dist/cjs/node-catalog/suggested-nodes-data.js +246 -0
- package/dist/cjs/node-catalog/suggested-nodes-data.js.map +1 -0
- package/dist/cjs/node-catalog/suggested.d.ts +3 -0
- package/dist/cjs/node-catalog/suggested.js +86 -0
- package/dist/cjs/node-catalog/suggested.js.map +1 -0
- package/dist/cjs/node-catalog/types.d.ts +17 -0
- package/dist/cjs/node-catalog/types.js +13 -0
- package/dist/cjs/node-catalog/types.js.map +1 -0
- package/dist/cjs/typecheck.tsbuildinfo +1 -1
- package/dist/cjs/utils/fromai-helpers.d.ts +4 -0
- package/dist/cjs/utils/fromai-helpers.js +33 -0
- package/dist/cjs/utils/fromai-helpers.js.map +1 -0
- package/dist/cjs/utils/fromai-tool-factory.d.ts +2 -4
- package/dist/cjs/utils/fromai-tool-factory.js +8 -23
- package/dist/cjs/utils/fromai-tool-factory.js.map +1 -1
- package/dist/cjs/utils/loaders/n8n-pdf-loader.d.ts +10 -0
- package/dist/cjs/utils/loaders/n8n-pdf-loader.js +100 -0
- package/dist/cjs/utils/loaders/n8n-pdf-loader.js.map +1 -0
- package/dist/cjs/utils/n8n-binary-loader.js +3 -3
- package/dist/cjs/utils/n8n-binary-loader.js.map +1 -1
- package/dist/esm/node-catalog/discriminator-utils.d.ts +22 -0
- package/dist/esm/node-catalog/discriminator-utils.js +85 -0
- package/dist/esm/node-catalog/discriminator-utils.js.map +1 -0
- package/dist/esm/node-catalog/get.d.ts +18 -0
- package/dist/esm/node-catalog/get.js +358 -0
- package/dist/esm/node-catalog/get.js.map +1 -0
- package/dist/esm/node-catalog/index.d.ts +14 -0
- package/dist/esm/node-catalog/index.js +30 -0
- package/dist/esm/node-catalog/index.js.map +1 -0
- package/dist/esm/node-catalog/lean-node-type.d.ts +27 -0
- package/dist/esm/node-catalog/lean-node-type.js +50 -0
- package/dist/esm/node-catalog/lean-node-type.js.map +1 -0
- package/dist/esm/node-catalog/node-type-parser.d.ts +20 -0
- package/dist/esm/node-catalog/node-type-parser.js +69 -0
- package/dist/esm/node-catalog/node-type-parser.js.map +1 -0
- package/dist/esm/node-catalog/resource-operation-extractor.d.ts +26 -0
- package/dist/esm/node-catalog/resource-operation-extractor.js +156 -0
- package/dist/esm/node-catalog/resource-operation-extractor.js.map +1 -0
- package/dist/esm/node-catalog/search-engine.d.ts +20 -0
- package/dist/esm/node-catalog/search-engine.js +247 -0
- package/dist/esm/node-catalog/search-engine.js.map +1 -0
- package/dist/esm/node-catalog/search.d.ts +10 -0
- package/dist/esm/node-catalog/search.js +321 -0
- package/dist/esm/node-catalog/search.js.map +1 -0
- package/dist/esm/node-catalog/suggested-nodes-data.d.ts +11 -0
- package/dist/esm/node-catalog/suggested-nodes-data.js +236 -0
- package/dist/esm/node-catalog/suggested-nodes-data.js.map +1 -0
- package/dist/esm/node-catalog/suggested.d.ts +3 -0
- package/dist/esm/node-catalog/suggested.js +76 -0
- package/dist/esm/node-catalog/suggested.js.map +1 -0
- package/dist/esm/node-catalog/types.d.ts +17 -0
- package/dist/esm/node-catalog/types.js +3 -0
- package/dist/esm/node-catalog/types.js.map +1 -0
- package/dist/esm/typecheck.tsbuildinfo +1 -1
- package/dist/esm/utils/fromai-helpers.d.ts +4 -0
- package/dist/esm/utils/fromai-helpers.js +23 -0
- package/dist/esm/utils/fromai-helpers.js.map +1 -0
- package/dist/esm/utils/fromai-tool-factory.d.ts +2 -4
- package/dist/esm/utils/fromai-tool-factory.js +7 -22
- package/dist/esm/utils/fromai-tool-factory.js.map +1 -1
- package/dist/esm/utils/loaders/n8n-pdf-loader.d.ts +10 -0
- package/dist/esm/utils/loaders/n8n-pdf-loader.js +89 -0
- package/dist/esm/utils/loaders/n8n-pdf-loader.js.map +1 -0
- package/dist/esm/utils/n8n-binary-loader.js +2 -2
- package/dist/esm/utils/n8n-binary-loader.js.map +1 -1
- package/package.json +30 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./discriminator-utils", "./resource-operation-extractor"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.toLeanNodeType = toLeanNodeType;
|
|
13
|
+
const discriminator_utils_1 = require("./discriminator-utils");
|
|
14
|
+
const resource_operation_extractor_1 = require("./resource-operation-extractor");
|
|
15
|
+
function getVersions(node) {
|
|
16
|
+
return Array.isArray(node.version) ? node.version : [node.version];
|
|
17
|
+
}
|
|
18
|
+
function buildVersionDiscriminators(node) {
|
|
19
|
+
const out = new Map();
|
|
20
|
+
for (const version of getVersions(node)) {
|
|
21
|
+
out.set(version, {
|
|
22
|
+
resourceOperations: (0, resource_operation_extractor_1.extractResourceOperations)(node, version, undefined, {
|
|
23
|
+
fields: { description: true, builderHint: true },
|
|
24
|
+
}),
|
|
25
|
+
modeDiscriminator: (0, discriminator_utils_1.extractModeDiscriminator)(node, version),
|
|
26
|
+
operationDiscriminator: (0, discriminator_utils_1.extractOperationOnlyDiscriminator)(node, version),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function toLeanNodeType(node) {
|
|
32
|
+
const lean = {
|
|
33
|
+
name: node.name,
|
|
34
|
+
displayName: node.displayName,
|
|
35
|
+
description: node.description,
|
|
36
|
+
version: node.version,
|
|
37
|
+
group: node.group,
|
|
38
|
+
inputs: node.inputs,
|
|
39
|
+
outputs: node.outputs,
|
|
40
|
+
discriminatorsByVersion: buildVersionDiscriminators(node),
|
|
41
|
+
};
|
|
42
|
+
if (node.codex?.alias) {
|
|
43
|
+
lean.codex = { alias: node.codex.alias };
|
|
44
|
+
}
|
|
45
|
+
if (node.builderHint) {
|
|
46
|
+
const { searchHint, relatedNodes, inputs } = node.builderHint;
|
|
47
|
+
const hint = {};
|
|
48
|
+
if (searchHint !== undefined)
|
|
49
|
+
hint.searchHint = searchHint;
|
|
50
|
+
if (relatedNodes !== undefined)
|
|
51
|
+
hint.relatedNodes = relatedNodes;
|
|
52
|
+
if (inputs !== undefined)
|
|
53
|
+
hint.inputs = inputs;
|
|
54
|
+
if (Object.keys(hint).length > 0)
|
|
55
|
+
lean.builderHint = hint;
|
|
56
|
+
}
|
|
57
|
+
return lean;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=lean-node-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lean-node-type.js","sourceRoot":"","sources":["../../../src/node-catalog/lean-node-type.ts"],"names":[],"mappings":";;;;;;;;;;;IAuFA,wCA0BC;IAhGD,+DAK+B;IAC/B,iFAGwC;IAmCxC,SAAS,WAAW,CAAC,IAA0B;QAC9C,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,SAAS,0BAA0B,CAClC,IAA0B;QAE1B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAiC,CAAC;QACrD,KAAK,MAAM,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YACzC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE;gBAChB,kBAAkB,EAAE,IAAA,wDAAyB,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE;oBACvE,MAAM,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;iBAChD,CAAC;gBACF,iBAAiB,EAAE,IAAA,8CAAwB,EAAC,IAAI,EAAE,OAAO,CAAC;gBAC1D,sBAAsB,EAAE,IAAA,uDAAiC,EAAC,IAAI,EAAE,OAAO,CAAC;aACxE,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;IAQD,SAAgB,cAAc,CAAC,IAA0B;QACxD,MAAM,IAAI,GAA4B;YACrC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,uBAAuB,EAAE,0BAA0B,CAAC,IAAI,CAAC;SACzD,CAAC;QAEF,IAAI,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC1C,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC;YAC9D,MAAM,IAAI,GAA2C,EAAE,CAAC;YACxD,IAAI,UAAU,KAAK,SAAS;gBAAE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC3D,IAAI,YAAY,KAAK,SAAS;gBAAE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;YACjE,IAAI,MAAM,KAAK,SAAS;gBAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YAC/C,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;gBAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
import { type LeanNodeTypeDescription, type VersionDiscriminators } from './lean-node-type';
|
|
3
|
+
export interface ParsedNodeType {
|
|
4
|
+
id: string;
|
|
5
|
+
displayName: string;
|
|
6
|
+
description: string;
|
|
7
|
+
version: number;
|
|
8
|
+
isTrigger: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class NodeTypeParser {
|
|
11
|
+
private nodeTypes;
|
|
12
|
+
private nodeTypeIndex;
|
|
13
|
+
private searchEngine;
|
|
14
|
+
constructor(nodeTypes: INodeTypeDescription[]);
|
|
15
|
+
private buildIndex;
|
|
16
|
+
private isTriggerNode;
|
|
17
|
+
searchNodeTypes(query: string, limit?: number, nodeFilter?: (nodeId: string) => boolean): ParsedNodeType[];
|
|
18
|
+
getLeanNodeType(nodeId: string, version?: number): LeanNodeTypeDescription | null;
|
|
19
|
+
getVersionDiscriminators(nodeId: string, version: number): VersionDiscriminators | null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./lean-node-type", "./search-engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NodeTypeParser = void 0;
|
|
13
|
+
const lean_node_type_1 = require("./lean-node-type");
|
|
14
|
+
const search_engine_1 = require("./search-engine");
|
|
15
|
+
class NodeTypeParser {
|
|
16
|
+
constructor(nodeTypes) {
|
|
17
|
+
this.nodeTypes = nodeTypes.map(lean_node_type_1.toLeanNodeType);
|
|
18
|
+
this.searchEngine = new search_engine_1.CodeBuilderNodeSearchEngine(this.nodeTypes);
|
|
19
|
+
this.nodeTypeIndex = this.buildIndex();
|
|
20
|
+
}
|
|
21
|
+
buildIndex() {
|
|
22
|
+
const index = new Map();
|
|
23
|
+
for (const nodeType of this.nodeTypes) {
|
|
24
|
+
const existing = index.get(nodeType.name) ?? [];
|
|
25
|
+
existing.push(nodeType);
|
|
26
|
+
index.set(nodeType.name, existing);
|
|
27
|
+
}
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
isTriggerNode(nodeType) {
|
|
31
|
+
if (nodeType.group.includes('trigger')) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return (nodeType.name.toLowerCase().includes('trigger') ||
|
|
35
|
+
nodeType.name.toLowerCase().includes('webhook'));
|
|
36
|
+
}
|
|
37
|
+
searchNodeTypes(query, limit = 5, nodeFilter) {
|
|
38
|
+
const results = this.searchEngine.searchByName(query, limit, nodeFilter);
|
|
39
|
+
return results.map((result) => {
|
|
40
|
+
const nodeType = this.getLeanNodeType(result.name, result.version);
|
|
41
|
+
return {
|
|
42
|
+
id: result.name,
|
|
43
|
+
displayName: result.displayName,
|
|
44
|
+
description: result.description,
|
|
45
|
+
version: result.version,
|
|
46
|
+
isTrigger: nodeType ? this.isTriggerNode(nodeType) : false,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getLeanNodeType(nodeId, version) {
|
|
51
|
+
const versions = this.nodeTypeIndex.get(nodeId);
|
|
52
|
+
if (!versions || versions.length === 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (version !== undefined) {
|
|
56
|
+
const match = versions.find((v) => {
|
|
57
|
+
const nodeVersions = Array.isArray(v.version) ? v.version : [v.version];
|
|
58
|
+
return nodeVersions.includes(version);
|
|
59
|
+
});
|
|
60
|
+
return match ?? null;
|
|
61
|
+
}
|
|
62
|
+
return versions.reduce((latest, current) => {
|
|
63
|
+
const latestMax = Array.isArray(latest.version)
|
|
64
|
+
? Math.max(...latest.version)
|
|
65
|
+
: latest.version;
|
|
66
|
+
const currentMax = Array.isArray(current.version)
|
|
67
|
+
? Math.max(...current.version)
|
|
68
|
+
: current.version;
|
|
69
|
+
return currentMax > latestMax ? current : latest;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
getVersionDiscriminators(nodeId, version) {
|
|
73
|
+
const node = this.getLeanNodeType(nodeId, version);
|
|
74
|
+
return node?.discriminatorsByVersion.get(version) ?? null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.NodeTypeParser = NodeTypeParser;
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=node-type-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-type-parser.js","sourceRoot":"","sources":["../../../src/node-catalog/node-type-parser.ts"],"names":[],"mappings":";;;;;;;;;;;;IAcA,qDAI0B;IAC1B,mDAA8D;IAc9D,MAAa,cAAc;QAK1B,YAAY,SAAiC;YAC5C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,+BAAc,CAAC,CAAC;YAC/C,IAAI,CAAC,YAAY,GAAG,IAAI,2CAA2B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,CAAC;QAKO,UAAU;YACjB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqC,CAAC;YAE3D,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACvC,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBAChD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACxB,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,KAAK,CAAC;QACd,CAAC;QAMO,aAAa,CAAC,QAAiC;YAEtD,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBACxC,OAAO,IAAI,CAAC;YACb,CAAC;YAED,OAAO,CACN,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAC/C,QAAQ,CAAC,IAAI,CAAC,WAAW,EA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AAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACvC,CAAC,CAAC,CAAC;gBACH,OAAO,KAAK,IAAI,IAAI,CAAC;YACtB,CAAC;YAGD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;gBAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;oBAC9C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;oBAC7B,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;gBAClB,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;oBAChD,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;oBAC9B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;gBACnB,OAAO,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;YAClD,CAAC,CAAC,CAAC;QACJ,CAAC;QAUD,wBAAwB,CAAC,MAAc,EAAE,OAAe;YACvD,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACnD,OAAO,IAAI,EAAE,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;QAC3D,CAAC;KACD;IAnHD,wCAmHC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type INodeTypeDescription, type IParameterBuilderHint, type Logger } from 'n8n-workflow';
|
|
2
|
+
export interface OperationInfo {
|
|
3
|
+
value: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
builderHint?: IParameterBuilderHint;
|
|
7
|
+
}
|
|
8
|
+
export interface ResourceInfo {
|
|
9
|
+
value: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
builderHint?: IParameterBuilderHint;
|
|
13
|
+
operations: OperationInfo[];
|
|
14
|
+
}
|
|
15
|
+
export interface ResourceOperationInfo {
|
|
16
|
+
resources: ResourceInfo[];
|
|
17
|
+
}
|
|
18
|
+
export interface ExtractOptions {
|
|
19
|
+
fields?: {
|
|
20
|
+
description?: boolean;
|
|
21
|
+
builderHint?: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare function extractResourceOperations(nodeType: INodeTypeDescription, nodeVersion: number, logger?: Logger, options?: ExtractOptions): ResourceOperationInfo | null;
|
|
25
|
+
export declare function createResourceCacheKey(nodeName: string, version: number): string;
|
|
26
|
+
export declare function formatResourceOperationsForPrompt(info: ResourceOperationInfo): string;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "n8n-workflow"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.extractResourceOperations = extractResourceOperations;
|
|
13
|
+
exports.createResourceCacheKey = createResourceCacheKey;
|
|
14
|
+
exports.formatResourceOperationsForPrompt = formatResourceOperationsForPrompt;
|
|
15
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
16
|
+
function isPropertyVisibleForVersion(property, nodeVersion) {
|
|
17
|
+
const displayOptions = property.displayOptions;
|
|
18
|
+
if (!displayOptions) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const showVersion = displayOptions.show?.['@version'];
|
|
22
|
+
if (showVersion && !(0, n8n_workflow_1.checkConditions)(showVersion, [nodeVersion])) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const hideVersion = displayOptions.hide?.['@version'];
|
|
26
|
+
if (hideVersion && (0, n8n_workflow_1.checkConditions)(hideVersion, [nodeVersion])) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
function findResourceProperty(properties, nodeVersion) {
|
|
32
|
+
return properties.find((prop) => prop.name === 'resource' &&
|
|
33
|
+
prop.type === 'options' &&
|
|
34
|
+
isPropertyVisibleForVersion(prop, nodeVersion));
|
|
35
|
+
}
|
|
36
|
+
function isOperationVisibleForResource(prop, resourceValue) {
|
|
37
|
+
const displayOptions = prop.displayOptions;
|
|
38
|
+
if (!displayOptions) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const showResource = displayOptions.show?.resource;
|
|
42
|
+
if (showResource && !(0, n8n_workflow_1.checkConditions)(showResource, [resourceValue])) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const hideResource = displayOptions.hide?.resource;
|
|
46
|
+
if (hideResource && (0, n8n_workflow_1.checkConditions)(hideResource, [resourceValue])) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function findOperationProperties(properties, resourceValue, nodeVersion) {
|
|
52
|
+
return properties.filter((prop) => {
|
|
53
|
+
if (prop.name !== 'operation' || prop.type !== 'options') {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!isPropertyVisibleForVersion(prop, nodeVersion)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return isOperationVisibleForResource(prop, resourceValue);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function extractOptions(property, logger, options) {
|
|
63
|
+
if (!property.options || !Array.isArray(property.options)) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const includeDescription = options?.fields?.description ?? false;
|
|
67
|
+
const includeBuilderHint = options?.fields?.builderHint ?? false;
|
|
68
|
+
return property.options
|
|
69
|
+
.filter((opt) => {
|
|
70
|
+
if (typeof opt !== 'object' || opt === null || !('name' in opt) || !('value' in opt)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const optName = opt.name;
|
|
74
|
+
const optValue = opt.value;
|
|
75
|
+
if (typeof optValue !== 'string') {
|
|
76
|
+
logger?.debug('Skipping non-string option value in resource/operation extraction', {
|
|
77
|
+
propertyName: property.name,
|
|
78
|
+
optionName: optName,
|
|
79
|
+
valueType: typeof optValue,
|
|
80
|
+
});
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
})
|
|
85
|
+
.map((opt) => ({
|
|
86
|
+
value: opt.value,
|
|
87
|
+
displayName: opt.name,
|
|
88
|
+
...(includeDescription && opt.description && { description: opt.description }),
|
|
89
|
+
...(includeBuilderHint && opt.builderHint && { builderHint: opt.builderHint }),
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
function extractResourceOperations(nodeType, nodeVersion, logger, options) {
|
|
93
|
+
const properties = nodeType.properties;
|
|
94
|
+
if (!properties || properties.length === 0) {
|
|
95
|
+
logger?.debug('extractResourceOperations: No properties found', {
|
|
96
|
+
nodeType: nodeType.name,
|
|
97
|
+
nodeVersion,
|
|
98
|
+
});
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const resourceProperty = findResourceProperty(properties, nodeVersion);
|
|
102
|
+
if (!resourceProperty) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const resourceOptions = extractOptions(resourceProperty, logger, options);
|
|
106
|
+
if (resourceOptions.length === 0) {
|
|
107
|
+
logger?.warn('extractResourceOperations: Resource property found but no string options', {
|
|
108
|
+
nodeType: nodeType.name,
|
|
109
|
+
nodeVersion,
|
|
110
|
+
propertyDefault: resourceProperty.default,
|
|
111
|
+
});
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const resources = resourceOptions.map((resource) => {
|
|
115
|
+
const operationProperties = findOperationProperties(properties, resource.value, nodeVersion);
|
|
116
|
+
const allOperations = [];
|
|
117
|
+
const seenValues = new Set();
|
|
118
|
+
for (const opProp of operationProperties) {
|
|
119
|
+
const ops = extractOptions(opProp, logger, options);
|
|
120
|
+
for (const op of ops) {
|
|
121
|
+
if (!seenValues.has(op.value)) {
|
|
122
|
+
seenValues.add(op.value);
|
|
123
|
+
allOperations.push({
|
|
124
|
+
value: op.value,
|
|
125
|
+
displayName: op.displayName,
|
|
126
|
+
...(op.description && { description: op.description }),
|
|
127
|
+
...(op.builderHint && { builderHint: op.builderHint }),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
value: resource.value,
|
|
134
|
+
displayName: resource.displayName,
|
|
135
|
+
...(resource.description && { description: resource.description }),
|
|
136
|
+
...(resource.builderHint && { builderHint: resource.builderHint }),
|
|
137
|
+
operations: allOperations,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
return { resources };
|
|
141
|
+
}
|
|
142
|
+
function createResourceCacheKey(nodeName, version) {
|
|
143
|
+
return `${nodeName}:${version}`;
|
|
144
|
+
}
|
|
145
|
+
function formatResourceOperationsForPrompt(info) {
|
|
146
|
+
const parts = ['<available_resources_and_operations>'];
|
|
147
|
+
for (const resource of info.resources) {
|
|
148
|
+
if (resource.value === '__CUSTOM_API_CALL__')
|
|
149
|
+
continue;
|
|
150
|
+
parts.push(` Resource: ${resource.displayName} (value: "${resource.value}")`);
|
|
151
|
+
const filteredOps = resource.operations.filter((op) => op.value !== '__CUSTOM_API_CALL__');
|
|
152
|
+
if (filteredOps.length > 0) {
|
|
153
|
+
parts.push(' Operations:');
|
|
154
|
+
for (const op of filteredOps) {
|
|
155
|
+
parts.push(` - ${op.displayName} (value: "${op.value}")`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
parts.push(' Operations: none defined');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
parts.push('</available_resources_and_operations>');
|
|
163
|
+
return parts.join('\n');
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=resource-operation-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-operation-extractor.js","sourceRoot":"","sources":["../../../src/node-catalog/resource-operation-extractor.ts"],"names":[],"mappings":";;;;;;;;;;;IAuNA,8DAkEC;IAMD,wDAEC;IAKD,8EAuBC;IA7TD,+CAMsB;IAiDtB,SAAS,2BAA2B,CAAC,QAAyB,EAAE,WAAmB;QAClF,MAAM,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC;QAG/C,IAAI,CAAC,cAAc,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACb,CAAC;QAGD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,WAAW,IAAI,CAAC,IAAA,8BAAe,EAAC,WAAW,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YACjE,OAAO,KAAK,CAAC;QACd,CAAC;QAGD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,WAAW,IAAI,IAAA,8BAAe,EAAC,WAAW,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YAChE,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAKD,SAAS,oBAAoB,CAC5B,UAA6B,EAC7B,WAAmB;QAEnB,OAAO,UAAU,CAAC,IAAI,CACrB,CAAC,IAAI,EAAE,EAAE,CACR,IAAI,CAAC,IAAI,KAAK,UAAU;YACxB,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,2BAA2B,CAAC,IAAI,EAAE,WAAW,CAAC,CAC/C,CAAC;IACH,CAAC;IAMD,SAAS,6BAA6B,CAAC,IAAqB,EAAE,aAA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AQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,qBAAqB,CAAC,CAAC;YAC3F,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;gBAC9B,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;oBAC9B,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,WAAW,aAAa,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;gBAChE,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,KAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAC5C,CAAC;QACF,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;QACpD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { INodeTypeDescription, NodeConnectionType } from 'n8n-workflow';
|
|
2
|
+
import { type LeanNodeTypeDescription } from './lean-node-type';
|
|
3
|
+
import type { CodeBuilderNodeSearchResult } from './types';
|
|
4
|
+
export declare const SCORE_WEIGHTS: {
|
|
5
|
+
readonly CONNECTION_EXACT: 100;
|
|
6
|
+
readonly CONNECTION_IN_EXPRESSION: 50;
|
|
7
|
+
};
|
|
8
|
+
export declare class CodeBuilderNodeSearchEngine {
|
|
9
|
+
private readonly nodeTypes;
|
|
10
|
+
constructor(nodeTypes: Array<INodeTypeDescription | LeanNodeTypeDescription>);
|
|
11
|
+
searchByName(query: string, limit?: number, nodeFilter?: (nodeId: string) => boolean): CodeBuilderNodeSearchResult[];
|
|
12
|
+
searchByConnectionType(connectionType: NodeConnectionType, limit?: number, nameFilter?: string): CodeBuilderNodeSearchResult[];
|
|
13
|
+
formatResult(result: CodeBuilderNodeSearchResult): string;
|
|
14
|
+
getSubnodesForConnectionType(connectionType: string): string[];
|
|
15
|
+
getRelatedSubnodeIds(nodeIds: string[], excludeNodeIds: Set<string>): Set<string>;
|
|
16
|
+
getNodeType(nodeId: string): LeanNodeTypeDescription | undefined;
|
|
17
|
+
private getConnectionScore;
|
|
18
|
+
static isAiConnectionType(connectionType: string): boolean;
|
|
19
|
+
static getAiConnectionTypes(): NodeConnectionType[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@n8n/utils", "n8n-workflow", "./lean-node-type"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CodeBuilderNodeSearchEngine = exports.SCORE_WEIGHTS = void 0;
|
|
13
|
+
const utils_1 = require("@n8n/utils");
|
|
14
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
15
|
+
const lean_node_type_1 = require("./lean-node-type");
|
|
16
|
+
function isLeanNodeType(node) {
|
|
17
|
+
return 'discriminatorsByVersion' in node;
|
|
18
|
+
}
|
|
19
|
+
function isNodeConnectionType(value) {
|
|
20
|
+
return Object.values(n8n_workflow_1.NodeConnectionTypes).includes(value);
|
|
21
|
+
}
|
|
22
|
+
const DEFAULT_SUBNODES = {
|
|
23
|
+
ai_languageModel: ['@n8n/n8n-nodes-langchain.lmChatOpenAi'],
|
|
24
|
+
ai_memory: ['@n8n/n8n-nodes-langchain.memoryBufferWindow'],
|
|
25
|
+
ai_embedding: ['@n8n/n8n-nodes-langchain.embeddingsOpenAi'],
|
|
26
|
+
ai_vectorStore: ['@n8n/n8n-nodes-langchain.vectorStoreInMemory'],
|
|
27
|
+
};
|
|
28
|
+
const NODE_SEARCH_KEYS = [
|
|
29
|
+
{ key: 'displayName', weight: 1.5 },
|
|
30
|
+
{ key: 'name', weight: 1.3 },
|
|
31
|
+
{ key: 'codex.alias', weight: 1.0 },
|
|
32
|
+
{ key: 'description', weight: 0.7 },
|
|
33
|
+
];
|
|
34
|
+
function getTypeName(nodeName) {
|
|
35
|
+
if (!nodeName)
|
|
36
|
+
return '';
|
|
37
|
+
const lastDotIndex = nodeName.lastIndexOf('.');
|
|
38
|
+
return lastDotIndex >= 0 ? nodeName.substring(lastDotIndex + 1) : nodeName;
|
|
39
|
+
}
|
|
40
|
+
exports.SCORE_WEIGHTS = {
|
|
41
|
+
CONNECTION_EXACT: 100,
|
|
42
|
+
CONNECTION_IN_EXPRESSION: 50,
|
|
43
|
+
};
|
|
44
|
+
function getLatestVersion(version) {
|
|
45
|
+
return Array.isArray(version) ? Math.max(...version) : version;
|
|
46
|
+
}
|
|
47
|
+
function extractSubnodeRequirements(inputs) {
|
|
48
|
+
if (!inputs)
|
|
49
|
+
return [];
|
|
50
|
+
return Object.entries(inputs).map(([connectionType, config]) => ({
|
|
51
|
+
connectionType,
|
|
52
|
+
required: config.required,
|
|
53
|
+
...(config.displayOptions && { displayOptions: config.displayOptions }),
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
function dedupeNodes(nodes) {
|
|
57
|
+
const dedupeCache = {};
|
|
58
|
+
nodes.forEach((node) => {
|
|
59
|
+
const cachedNodeType = dedupeCache[node.name];
|
|
60
|
+
if (!cachedNodeType) {
|
|
61
|
+
dedupeCache[node.name] = node;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const cachedVersion = getLatestVersion(cachedNodeType.version);
|
|
65
|
+
const nextVersion = getLatestVersion(node.version);
|
|
66
|
+
if (nextVersion > cachedVersion) {
|
|
67
|
+
dedupeCache[node.name] = node;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return Object.values(dedupeCache);
|
|
71
|
+
}
|
|
72
|
+
class CodeBuilderNodeSearchEngine {
|
|
73
|
+
constructor(nodeTypes) {
|
|
74
|
+
const lean = nodeTypes.map((n) => (isLeanNodeType(n) ? n : (0, lean_node_type_1.toLeanNodeType)(n)));
|
|
75
|
+
this.nodeTypes = dedupeNodes(lean);
|
|
76
|
+
}
|
|
77
|
+
searchByName(query, limit = 20, nodeFilter) {
|
|
78
|
+
const nodeTypes = nodeFilter
|
|
79
|
+
? this.nodeTypes.filter((node) => nodeFilter(node.name))
|
|
80
|
+
: this.nodeTypes;
|
|
81
|
+
const searchResults = (0, utils_1.sublimeSearch)(query, nodeTypes, NODE_SEARCH_KEYS);
|
|
82
|
+
const queryLower = query.toLowerCase().trim();
|
|
83
|
+
const fuzzyResultNames = new Set(searchResults.map((r) => r.item.name));
|
|
84
|
+
const typeNameMatches = nodeTypes
|
|
85
|
+
.filter((node) => {
|
|
86
|
+
if (fuzzyResultNames.has(node.name))
|
|
87
|
+
return false;
|
|
88
|
+
return getTypeName(node.name).toLowerCase() === queryLower;
|
|
89
|
+
})
|
|
90
|
+
.map((item) => ({ item, score: 0 }));
|
|
91
|
+
const allResults = [...searchResults, ...typeNameMatches];
|
|
92
|
+
allResults.sort((a, b) => {
|
|
93
|
+
const exactA = getTypeName(a.item.name).toLowerCase() === queryLower;
|
|
94
|
+
const exactB = getTypeName(b.item.name).toLowerCase() === queryLower;
|
|
95
|
+
if (exactA && !exactB)
|
|
96
|
+
return -1;
|
|
97
|
+
if (!exactA && exactB)
|
|
98
|
+
return 1;
|
|
99
|
+
return b.score - a.score;
|
|
100
|
+
});
|
|
101
|
+
return allResults
|
|
102
|
+
.slice(0, limit)
|
|
103
|
+
.map(({ item, score, }) => {
|
|
104
|
+
const subnodeRequirements = extractSubnodeRequirements(item.builderHint?.inputs);
|
|
105
|
+
return {
|
|
106
|
+
name: item.name,
|
|
107
|
+
displayName: item.displayName,
|
|
108
|
+
description: item.description ?? 'No description available',
|
|
109
|
+
version: getLatestVersion(item.version),
|
|
110
|
+
inputs: item.inputs,
|
|
111
|
+
outputs: item.outputs,
|
|
112
|
+
score,
|
|
113
|
+
...(item.builderHint?.searchHint && {
|
|
114
|
+
builderHintMessage: item.builderHint.searchHint,
|
|
115
|
+
}),
|
|
116
|
+
...(subnodeRequirements.length > 0 && { subnodeRequirements }),
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
searchByConnectionType(connectionType, limit = 20, nameFilter) {
|
|
121
|
+
const nodesWithConnectionType = this.nodeTypes
|
|
122
|
+
.map((nodeType) => {
|
|
123
|
+
const connectionScore = this.getConnectionScore(nodeType, connectionType);
|
|
124
|
+
return connectionScore > 0 ? { nodeType, connectionScore } : null;
|
|
125
|
+
})
|
|
126
|
+
.filter((result) => Boolean(result));
|
|
127
|
+
if (!nameFilter) {
|
|
128
|
+
return nodesWithConnectionType
|
|
129
|
+
.sort((a, b) => b.connectionScore - a.connectionScore)
|
|
130
|
+
.slice(0, limit)
|
|
131
|
+
.map(({ nodeType, connectionScore }) => {
|
|
132
|
+
const subnodeRequirements = extractSubnodeRequirements(nodeType.builderHint?.inputs);
|
|
133
|
+
return {
|
|
134
|
+
name: nodeType.name,
|
|
135
|
+
displayName: nodeType.displayName,
|
|
136
|
+
version: getLatestVersion(nodeType.version),
|
|
137
|
+
description: nodeType.description ?? 'No description available',
|
|
138
|
+
inputs: nodeType.inputs,
|
|
139
|
+
outputs: nodeType.outputs,
|
|
140
|
+
score: connectionScore,
|
|
141
|
+
...(nodeType.builderHint?.searchHint && {
|
|
142
|
+
builderHintMessage: nodeType.builderHint.searchHint,
|
|
143
|
+
}),
|
|
144
|
+
...(subnodeRequirements.length > 0 && { subnodeRequirements }),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const nodeTypesOnly = nodesWithConnectionType.map((result) => result.nodeType);
|
|
149
|
+
const nameFilteredResults = (0, utils_1.sublimeSearch)(nameFilter, nodeTypesOnly, NODE_SEARCH_KEYS);
|
|
150
|
+
return nameFilteredResults
|
|
151
|
+
.slice(0, limit)
|
|
152
|
+
.map(({ item, score: nameScore }) => {
|
|
153
|
+
const connectionResult = nodesWithConnectionType.find((result) => result.nodeType.name === item.name);
|
|
154
|
+
const connectionScore = connectionResult?.connectionScore ?? 0;
|
|
155
|
+
const subnodeRequirements = extractSubnodeRequirements(item.builderHint?.inputs);
|
|
156
|
+
return {
|
|
157
|
+
name: item.name,
|
|
158
|
+
version: getLatestVersion(item.version),
|
|
159
|
+
displayName: item.displayName,
|
|
160
|
+
description: item.description ?? 'No description available',
|
|
161
|
+
inputs: item.inputs,
|
|
162
|
+
outputs: item.outputs,
|
|
163
|
+
score: connectionScore + nameScore,
|
|
164
|
+
...(item.builderHint?.searchHint && {
|
|
165
|
+
builderHintMessage: item.builderHint.searchHint,
|
|
166
|
+
}),
|
|
167
|
+
...(subnodeRequirements.length > 0 && { subnodeRequirements }),
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
formatResult(result) {
|
|
172
|
+
const parts = [
|
|
173
|
+
' <node>',
|
|
174
|
+
` <node_name>${result.name}</node_name>`,
|
|
175
|
+
` <node_version>${result.version}</node_version>`,
|
|
176
|
+
` <node_description>${result.description}</node_description>`,
|
|
177
|
+
` <node_inputs>${typeof result.inputs === 'object' ? JSON.stringify(result.inputs) : result.inputs}</node_inputs>`,
|
|
178
|
+
` <node_outputs>${typeof result.outputs === 'object' ? JSON.stringify(result.outputs) : result.outputs}</node_outputs>`,
|
|
179
|
+
];
|
|
180
|
+
if (result.builderHintMessage) {
|
|
181
|
+
parts.push(` <builder_hint>${result.builderHintMessage}</builder_hint>`);
|
|
182
|
+
}
|
|
183
|
+
if (result.subnodeRequirements && result.subnodeRequirements.length > 0) {
|
|
184
|
+
parts.push(' <subnode_requirements>');
|
|
185
|
+
for (const req of result.subnodeRequirements) {
|
|
186
|
+
const requiredStr = req.required ? 'required' : 'optional';
|
|
187
|
+
if (req.displayOptions) {
|
|
188
|
+
parts.push(` <requirement type="${req.connectionType}" status="${requiredStr}"><display_options>${JSON.stringify(req.displayOptions)}</display_options></requirement>`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
parts.push(' <requirement type="' +
|
|
192
|
+
req.connectionType +
|
|
193
|
+
'" status="' +
|
|
194
|
+
requiredStr +
|
|
195
|
+
'" />');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
parts.push(' </subnode_requirements>');
|
|
199
|
+
}
|
|
200
|
+
parts.push(' </node>');
|
|
201
|
+
return '\n' + parts.join('\n');
|
|
202
|
+
}
|
|
203
|
+
getSubnodesForConnectionType(connectionType) {
|
|
204
|
+
return DEFAULT_SUBNODES[connectionType] ?? [];
|
|
205
|
+
}
|
|
206
|
+
getRelatedSubnodeIds(nodeIds, excludeNodeIds) {
|
|
207
|
+
const allRelated = new Set();
|
|
208
|
+
const visited = new Set(excludeNodeIds);
|
|
209
|
+
for (const nodeId of nodeIds) {
|
|
210
|
+
visited.add(nodeId);
|
|
211
|
+
}
|
|
212
|
+
const queue = [...nodeIds];
|
|
213
|
+
while (queue.length > 0) {
|
|
214
|
+
const currentNodeId = queue.shift();
|
|
215
|
+
const nodeType = this.nodeTypes.find((n) => n.name === currentNodeId);
|
|
216
|
+
if (!nodeType?.builderHint?.inputs)
|
|
217
|
+
continue;
|
|
218
|
+
for (const connectionType of Object.keys(nodeType.builderHint.inputs)) {
|
|
219
|
+
const subnodeIds = this.getSubnodesForConnectionType(connectionType);
|
|
220
|
+
for (const subnodeId of subnodeIds) {
|
|
221
|
+
if (visited.has(subnodeId))
|
|
222
|
+
continue;
|
|
223
|
+
visited.add(subnodeId);
|
|
224
|
+
allRelated.add(subnodeId);
|
|
225
|
+
queue.push(subnodeId);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return allRelated;
|
|
230
|
+
}
|
|
231
|
+
getNodeType(nodeId) {
|
|
232
|
+
return this.nodeTypes.find((n) => n.name === nodeId);
|
|
233
|
+
}
|
|
234
|
+
getConnectionScore(nodeType, connectionType) {
|
|
235
|
+
const outputs = nodeType.outputs;
|
|
236
|
+
if (Array.isArray(outputs)) {
|
|
237
|
+
if (outputs.includes(connectionType)) {
|
|
238
|
+
return exports.SCORE_WEIGHTS.CONNECTION_EXACT;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (typeof outputs === 'string') {
|
|
242
|
+
if (outputs.includes(connectionType)) {
|
|
243
|
+
return exports.SCORE_WEIGHTS.CONNECTION_IN_EXPRESSION;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
static isAiConnectionType(connectionType) {
|
|
249
|
+
return connectionType.startsWith('ai_');
|
|
250
|
+
}
|
|
251
|
+
static getAiConnectionTypes() {
|
|
252
|
+
return Object.values(n8n_workflow_1.NodeConnectionTypes).filter((type) => isNodeConnectionType(type) && CodeBuilderNodeSearchEngine.isAiConnectionType(type));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.CodeBuilderNodeSearchEngine = CodeBuilderNodeSearchEngine;
|
|
256
|
+
});
|
|
257
|
+
//# sourceMappingURL=search-engine.js.map
|