@n8n/ai-workflow-builder 0.28.0 → 0.30.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/build.tsbuildinfo +1 -1
- package/dist/chains/prompt-categorization.d.ts +3 -0
- package/dist/chains/prompt-categorization.js +109 -0
- package/dist/chains/prompt-categorization.js.map +1 -0
- package/dist/chains/test/integration/test-helpers.d.ts +3 -0
- package/dist/chains/test/integration/test-helpers.js +16 -0
- package/dist/chains/test/integration/test-helpers.js.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/llm-config.js +13 -0
- package/dist/llm-config.js.map +1 -1
- package/dist/tools/add-node.tool.d.ts +29 -0
- package/dist/tools/add-node.tool.js +26 -8
- package/dist/tools/add-node.tool.js.map +1 -1
- package/dist/tools/best-practices/chatbot.d.ts +7 -0
- package/dist/tools/best-practices/chatbot.js +118 -0
- package/dist/tools/best-practices/chatbot.js.map +1 -0
- package/dist/tools/best-practices/content-generation.d.ts +7 -0
- package/dist/tools/best-practices/content-generation.js +79 -0
- package/dist/tools/best-practices/content-generation.js.map +1 -0
- package/dist/tools/best-practices/data-extraction.d.ts +7 -0
- package/dist/tools/best-practices/data-extraction.js +105 -0
- package/dist/tools/best-practices/data-extraction.js.map +1 -0
- package/dist/tools/best-practices/form-input.d.ts +7 -0
- package/dist/tools/best-practices/form-input.js +173 -0
- package/dist/tools/best-practices/form-input.js.map +1 -0
- package/dist/tools/best-practices/index.d.ts +3 -0
- package/dist/tools/best-practices/index.js +27 -0
- package/dist/tools/best-practices/index.js.map +1 -0
- package/dist/tools/best-practices/scraping-and-research.d.ts +7 -0
- package/dist/tools/best-practices/scraping-and-research.js +147 -0
- package/dist/tools/best-practices/scraping-and-research.js.map +1 -0
- package/dist/tools/builder-tools.js +6 -0
- package/dist/tools/builder-tools.js.map +1 -1
- package/dist/tools/categorize-prompt.tool.d.ts +5 -0
- package/dist/tools/categorize-prompt.tool.js +84 -0
- package/dist/tools/categorize-prompt.tool.js.map +1 -0
- package/dist/tools/engines/node-search-engine.d.ts +0 -9
- package/dist/tools/engines/node-search-engine.js +74 -73
- package/dist/tools/engines/node-search-engine.js.map +1 -1
- package/dist/tools/get-best-practices.tool.d.ts +33 -0
- package/dist/tools/get-best-practices.tool.js +94 -0
- package/dist/tools/get-best-practices.tool.js.map +1 -0
- package/dist/tools/helpers/validation.d.ts +1 -1
- package/dist/tools/helpers/validation.js +3 -2
- package/dist/tools/helpers/validation.js.map +1 -1
- package/dist/tools/node-details.tool.d.ts +4 -0
- package/dist/tools/node-details.tool.js +3 -2
- package/dist/tools/node-details.tool.js.map +1 -1
- package/dist/tools/prompts/main-agent.prompt.js +23 -5
- package/dist/tools/prompts/main-agent.prompt.js.map +1 -1
- package/dist/tools/update-node-parameters.tool.js +1 -1
- package/dist/tools/update-node-parameters.tool.js.map +1 -1
- package/dist/tools/utils/node-creation.utils.d.ts +2 -2
- package/dist/tools/utils/node-creation.utils.js +7 -3
- package/dist/tools/utils/node-creation.utils.js.map +1 -1
- package/dist/tools/validate-workflow.tool.js +0 -16
- package/dist/tools/validate-workflow.tool.js.map +1 -1
- package/dist/types/best-practices.d.ts +6 -0
- package/dist/types/best-practices.js +3 -0
- package/dist/types/best-practices.js.map +1 -0
- package/dist/types/categorization.d.ts +23 -0
- package/dist/types/categorization.js +38 -0
- package/dist/types/categorization.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/nodes.d.ts +1 -0
- package/dist/types/tools.d.ts +4 -0
- package/dist/utils/http-proxy-agent.d.ts +2 -0
- package/dist/utils/http-proxy-agent.js +16 -0
- package/dist/utils/http-proxy-agent.js.map +1 -0
- package/dist/utils/stream-processor.js +85 -58
- package/dist/utils/stream-processor.js.map +1 -1
- package/dist/validation/checks/agent-prompt.js +1 -1
- package/dist/validation/checks/agent-prompt.js.map +1 -1
- package/dist/validation/checks/connections.js +32 -1
- package/dist/validation/checks/connections.js.map +1 -1
- package/dist/workflow-builder-agent.js +30 -22
- package/dist/workflow-builder-agent.js.map +1 -1
- package/dist/workflow-state.d.ts +1 -1
- package/dist/workflow-state.js.map +1 -1
- package/package.json +10 -6
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import { type PromptCategorization } from '../types/categorization';
|
|
3
|
+
export declare function promptCategorizationChain(llm: BaseChatModel, userPrompt: string): Promise<PromptCategorization>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptCategorizationChain = promptCategorizationChain;
|
|
4
|
+
const prompts_1 = require("@langchain/core/prompts");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const categorization_1 = require("../types/categorization");
|
|
7
|
+
const examplePrompts = [
|
|
8
|
+
{
|
|
9
|
+
prompt: 'Monitor social channels for product mentions and auto-respond with campaign messages',
|
|
10
|
+
techniques: [
|
|
11
|
+
categorization_1.WorkflowTechnique.MONITORING,
|
|
12
|
+
categorization_1.WorkflowTechnique.CHATBOT,
|
|
13
|
+
categorization_1.WorkflowTechnique.CONTENT_GENERATION,
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
prompt: 'Collect partner referral submissions and verify client instances via BigQuery',
|
|
18
|
+
techniques: [
|
|
19
|
+
categorization_1.WorkflowTechnique.FORM_INPUT,
|
|
20
|
+
categorization_1.WorkflowTechnique.HUMAN_IN_THE_LOOP,
|
|
21
|
+
categorization_1.WorkflowTechnique.NOTIFICATION,
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
prompt: 'Scrape competitor pricing pages weekly and generate a summary report of changes',
|
|
26
|
+
techniques: [
|
|
27
|
+
categorization_1.WorkflowTechnique.SCHEDULING,
|
|
28
|
+
categorization_1.WorkflowTechnique.SCRAPING_AND_RESEARCH,
|
|
29
|
+
categorization_1.WorkflowTechnique.DATA_EXTRACTION,
|
|
30
|
+
categorization_1.WorkflowTechnique.DATA_ANALYSIS,
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
prompt: 'Process uploaded PDF contracts to extract client details and update CRM records',
|
|
35
|
+
techniques: [
|
|
36
|
+
categorization_1.WorkflowTechnique.DOCUMENT_PROCESSING,
|
|
37
|
+
categorization_1.WorkflowTechnique.DATA_EXTRACTION,
|
|
38
|
+
categorization_1.WorkflowTechnique.DATA_TRANSFORMATION,
|
|
39
|
+
categorization_1.WorkflowTechnique.ENRICHMENT,
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
prompt: 'Build a searchable internal knowledge base from past support tickets',
|
|
44
|
+
techniques: [
|
|
45
|
+
categorization_1.WorkflowTechnique.DATA_TRANSFORMATION,
|
|
46
|
+
categorization_1.WorkflowTechnique.DATA_ANALYSIS,
|
|
47
|
+
categorization_1.WorkflowTechnique.KNOWLEDGE_BASE,
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
function formatExamplePrompts() {
|
|
52
|
+
return examplePrompts
|
|
53
|
+
.map((example) => `- ${example.prompt} → ${example.techniques.join(',')}`)
|
|
54
|
+
.join('\n');
|
|
55
|
+
}
|
|
56
|
+
const promptCategorizationTemplate = prompts_1.PromptTemplate.fromTemplate(`Analyze the following user prompt and identify the workflow techniques required to fulfill the request.
|
|
57
|
+
Be specific and identify all relevant techniques.
|
|
58
|
+
|
|
59
|
+
<user_prompt>
|
|
60
|
+
{userPrompt}
|
|
61
|
+
</user_prompt>
|
|
62
|
+
|
|
63
|
+
<workflow_techniques>
|
|
64
|
+
{techniques}
|
|
65
|
+
</workflow_techniques>
|
|
66
|
+
|
|
67
|
+
The following prompt categorization examples show a prompt → techniques involved to provide a sense
|
|
68
|
+
of how the categorization should be carried out.
|
|
69
|
+
<example_categorization>
|
|
70
|
+
${formatExamplePrompts()}
|
|
71
|
+
</example_categorization>
|
|
72
|
+
|
|
73
|
+
Select a maximum of 5 techniques that you believe are applicable, but only select them if you are
|
|
74
|
+
confident that they are applicable. If the prompt is ambigious or does not provide an obvious workflow
|
|
75
|
+
do not provide any techniques - if confidence is low avoid providing techniques.
|
|
76
|
+
|
|
77
|
+
Select ALL techniques that apply to this workflow. Most workflows use multiple techniques.
|
|
78
|
+
Rate your confidence in this categorization from 0.0 to 1.0.
|
|
79
|
+
`);
|
|
80
|
+
function formatTechniqueList() {
|
|
81
|
+
return Object.entries(categorization_1.TechniqueDescription)
|
|
82
|
+
.map(([key, description]) => `- **${key}**: ${description}`)
|
|
83
|
+
.join('\n');
|
|
84
|
+
}
|
|
85
|
+
async function promptCategorizationChain(llm, userPrompt) {
|
|
86
|
+
const categorizationSchema = zod_1.z.object({
|
|
87
|
+
techniques: zod_1.z
|
|
88
|
+
.array(zod_1.z.nativeEnum(categorization_1.WorkflowTechnique))
|
|
89
|
+
.min(0)
|
|
90
|
+
.max(5)
|
|
91
|
+
.describe('Zero to five workflow techniques identified in the prompt (maximum of 5)'),
|
|
92
|
+
confidence: zod_1.z
|
|
93
|
+
.number()
|
|
94
|
+
.min(0)
|
|
95
|
+
.max(1)
|
|
96
|
+
.describe('Confidence level in this categorization from 0.0 to 1.0'),
|
|
97
|
+
});
|
|
98
|
+
const modelWithStructure = llm.withStructuredOutput(categorizationSchema);
|
|
99
|
+
const prompt = await promptCategorizationTemplate.invoke({
|
|
100
|
+
userPrompt,
|
|
101
|
+
techniques: formatTechniqueList(),
|
|
102
|
+
});
|
|
103
|
+
const structuredOutput = await modelWithStructure.invoke(prompt);
|
|
104
|
+
return {
|
|
105
|
+
techniques: structuredOutput.techniques,
|
|
106
|
+
confidence: structuredOutput.confidence,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=prompt-categorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-categorization.js","sourceRoot":"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,CACA,CAAC;AAEF,SAAS,mBAAmB;IAC3B,OAAO,MAAM,CAAC,OAAO,CAAC,qCAAoB,CAAC;SACzC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,OAAO,GAAG,OAAO,WAAW,EAAE,CAAC;SAC3D,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAEM,KAAK,UAAU,yBAAyB,CAC9C,GAAkB,EAClB,UAAkB;IAElB,MAAM,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;QACrC,UAAU,EAAE,OAAC;aACX,KAAK,CAAC,OAAC,CAAC,UAAU,CAAC,kCAAiB,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,0EAA0E,CAAC;QACtF,UAAU,EAAE,OAAC;aACX,MAAM,EAAE;aACR,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,yDAAyD,CAAC;KACrE,CAAC,CAAC;IAEH,MAAM,kBAAkB,GAAG,GAAG,CAAC,oBAAoB,CAAuB,oBAAoB,CAAC,CAAC;IAEhG,MAAM,MAAM,GAAG,MAAM,4BAA4B,CAAC,MAAM,CAAC;QACxD,UAAU;QACV,UAAU,EAAE,mBAAmB,EAAE;KACjC,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAG,MAAM,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjE,OAAO;QACN,UAAU,EAAE,gBAAgB,CAAC,UAAU;QACvC,UAAU,EAAE,gBAAgB,CAAC,UAAU;KACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupIntegrationLLM = setupIntegrationLLM;
|
|
4
|
+
exports.shouldRunIntegrationTests = shouldRunIntegrationTests;
|
|
5
|
+
const llm_config_1 = require("../../../llm-config");
|
|
6
|
+
async function setupIntegrationLLM() {
|
|
7
|
+
const apiKey = process.env.N8N_AI_ANTHROPIC_KEY;
|
|
8
|
+
if (!apiKey) {
|
|
9
|
+
throw new Error('N8N_AI_ANTHROPIC_KEY environment variable is required for integration tests');
|
|
10
|
+
}
|
|
11
|
+
return await (0, llm_config_1.anthropicClaudeSonnet45)({ apiKey });
|
|
12
|
+
}
|
|
13
|
+
function shouldRunIntegrationTests() {
|
|
14
|
+
return process.env.ENABLE_INTEGRATION_TESTS === 'true';
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=test-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../../../src/chains/test/integration/test-helpers.ts"],"names":[],"mappings":";;AAWA,kDAMC;AAQD,8DAEC;AAzBD,6CAAuD;AAShD,KAAK,UAAU,mBAAmB;IACxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAChD,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,MAAM,IAAA,oCAAuB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAClD,CAAC;AAQD,SAAgB,yBAAyB;IACxC,OAAO,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,MAAM,CAAC;AACxD,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export declare const MAX_INPUT_TOKENS: number;
|
|
|
5
5
|
export declare const MAX_PARAMETER_VALUE_LENGTH = 30000;
|
|
6
6
|
export declare const DEFAULT_AUTO_COMPACT_THRESHOLD_TOKENS: number;
|
|
7
7
|
export declare const MAX_WORKFLOW_LENGTH_TOKENS = 30000;
|
|
8
|
-
export declare const AVG_CHARS_PER_TOKEN_ANTHROPIC =
|
|
8
|
+
export declare const AVG_CHARS_PER_TOKEN_ANTHROPIC = 3.5;
|
package/dist/constants.js
CHANGED
|
@@ -8,5 +8,5 @@ exports.MAX_INPUT_TOKENS = exports.MAX_TOTAL_TOKENS - exports.MAX_OUTPUT_TOKENS
|
|
|
8
8
|
exports.MAX_PARAMETER_VALUE_LENGTH = 30_000;
|
|
9
9
|
exports.DEFAULT_AUTO_COMPACT_THRESHOLD_TOKENS = exports.MAX_TOTAL_TOKENS - 50_000;
|
|
10
10
|
exports.MAX_WORKFLOW_LENGTH_TOKENS = 30_000;
|
|
11
|
-
exports.AVG_CHARS_PER_TOKEN_ANTHROPIC =
|
|
11
|
+
exports.AVG_CHARS_PER_TOKEN_ANTHROPIC = 3.5;
|
|
12
12
|
//# sourceMappingURL=constants.js.map
|
package/dist/llm-config.js
CHANGED
|
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.anthropicClaudeSonnet45 = exports.gpt41 = exports.gpt41mini = exports.o4mini = void 0;
|
|
37
37
|
const constants_1 = require("./constants");
|
|
38
|
+
const http_proxy_agent_1 = require("./utils/http-proxy-agent");
|
|
38
39
|
const o4mini = async (config) => {
|
|
39
40
|
const { ChatOpenAI } = await Promise.resolve().then(() => __importStar(require('@langchain/openai')));
|
|
40
41
|
return new ChatOpenAI({
|
|
@@ -43,6 +44,9 @@ const o4mini = async (config) => {
|
|
|
43
44
|
configuration: {
|
|
44
45
|
baseURL: config.baseUrl,
|
|
45
46
|
defaultHeaders: config.headers,
|
|
47
|
+
fetchOptions: {
|
|
48
|
+
dispatcher: (0, http_proxy_agent_1.getProxyAgent)(config.baseUrl ?? 'https://api.openai.com/v1'),
|
|
49
|
+
},
|
|
46
50
|
},
|
|
47
51
|
});
|
|
48
52
|
};
|
|
@@ -57,6 +61,9 @@ const gpt41mini = async (config) => {
|
|
|
57
61
|
configuration: {
|
|
58
62
|
baseURL: config.baseUrl,
|
|
59
63
|
defaultHeaders: config.headers,
|
|
64
|
+
fetchOptions: {
|
|
65
|
+
dispatcher: (0, http_proxy_agent_1.getProxyAgent)(config.baseUrl ?? 'https://api.openai.com/v1'),
|
|
66
|
+
},
|
|
60
67
|
},
|
|
61
68
|
});
|
|
62
69
|
};
|
|
@@ -71,6 +78,9 @@ const gpt41 = async (config) => {
|
|
|
71
78
|
configuration: {
|
|
72
79
|
baseURL: config.baseUrl,
|
|
73
80
|
defaultHeaders: config.headers,
|
|
81
|
+
fetchOptions: {
|
|
82
|
+
dispatcher: (0, http_proxy_agent_1.getProxyAgent)(config.baseUrl ?? 'https://api.openai.com/v1'),
|
|
83
|
+
},
|
|
74
84
|
},
|
|
75
85
|
});
|
|
76
86
|
};
|
|
@@ -85,6 +95,9 @@ const anthropicClaudeSonnet45 = async (config) => {
|
|
|
85
95
|
anthropicApiUrl: config.baseUrl,
|
|
86
96
|
clientOptions: {
|
|
87
97
|
defaultHeaders: config.headers,
|
|
98
|
+
fetchOptions: {
|
|
99
|
+
dispatcher: (0, http_proxy_agent_1.getProxyAgent)(config.baseUrl),
|
|
100
|
+
},
|
|
88
101
|
},
|
|
89
102
|
});
|
|
90
103
|
delete model.topP;
|
package/dist/llm-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-config.js","sourceRoot":"","sources":["../src/llm-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAgD;
|
|
1
|
+
{"version":3,"file":"llm-config.js","sourceRoot":"","sources":["../src/llm-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAgD;AAEhD,+DAAyD;AAQlD,MAAM,MAAM,GAAG,KAAK,EAAE,MAAyB,EAAE,EAAE;IACzD,MAAM,EAAE,UAAU,EAAE,GAAG,wDAAa,mBAAmB,GAAC,CAAC;IACzD,OAAO,IAAI,UAAU,CAAC;QAC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gCAAa,EAAC,MAAM,CAAC,OAAO,IAAI,2BAA2B,CAAC;aACxE;SACD;KACD,CAAC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,KAAK,SAehB;AAEK,MAAM,uBAAuB,GAAG,KAAK,EAAE,MAAyB,EAAE,EAAE;IAC1E,MAAM,EAAE,aAAa,EAAE,GAAG,wDAAa,sBAAsB,GAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC;QAC/B,KAAK,EAAE,mBAAmB;QAC1B,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,WAAW,EAAE,CAAC;QACd,SAAS,EAAE,6BAAiB;QAC5B,eAAe,EAAE,MAAM,CAAC,OAAO;QAC/B,aAAa,EAAE;YACd,cAAc,EAAE,MAAM,CAAC,OAAO;YAC9B,YAAY,EAAE;gBACb,UAAU,EAAE,IAAA,gCAAa,EAAC,MAAM,CAAC,OAAO,CAAC;aACzC;SACD;KACD,CAAC,CAAC;IAGH,OAAO,KAAK,CAAC,IAAI,CAAC;IAElB,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AApBW,QAAA,uBAAuB,2BAoBlC"}
|
|
@@ -3,12 +3,14 @@ import { z } from 'zod';
|
|
|
3
3
|
import type { BuilderTool, BuilderToolBase } from '../utils/stream-processor';
|
|
4
4
|
export declare const nodeCreationSchema: z.ZodObject<{
|
|
5
5
|
nodeType: z.ZodString;
|
|
6
|
+
nodeVersion: z.ZodNumber;
|
|
6
7
|
name: z.ZodString;
|
|
7
8
|
connectionParametersReasoning: z.ZodString;
|
|
8
9
|
connectionParameters: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
|
|
9
10
|
}, "strip", z.ZodTypeAny, {
|
|
10
11
|
nodeType: string;
|
|
11
12
|
name: string;
|
|
13
|
+
nodeVersion: number;
|
|
12
14
|
connectionParametersReasoning: string;
|
|
13
15
|
connectionParameters: {} & {
|
|
14
16
|
[k: string]: unknown;
|
|
@@ -16,10 +18,37 @@ export declare const nodeCreationSchema: z.ZodObject<{
|
|
|
16
18
|
}, {
|
|
17
19
|
nodeType: string;
|
|
18
20
|
name: string;
|
|
21
|
+
nodeVersion: number;
|
|
19
22
|
connectionParametersReasoning: string;
|
|
20
23
|
connectionParameters: {} & {
|
|
21
24
|
[k: string]: unknown;
|
|
22
25
|
};
|
|
23
26
|
}>;
|
|
27
|
+
export declare const nodeCreationE2ESchema: z.ZodObject<{
|
|
28
|
+
id: z.ZodOptional<z.ZodString>;
|
|
29
|
+
nodeType: z.ZodString;
|
|
30
|
+
nodeVersion: z.ZodNumber;
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
connectionParametersReasoning: z.ZodString;
|
|
33
|
+
connectionParameters: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
nodeType: string;
|
|
36
|
+
name: string;
|
|
37
|
+
nodeVersion: number;
|
|
38
|
+
connectionParametersReasoning: string;
|
|
39
|
+
connectionParameters: {} & {
|
|
40
|
+
[k: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
id?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
nodeType: string;
|
|
45
|
+
name: string;
|
|
46
|
+
nodeVersion: number;
|
|
47
|
+
connectionParametersReasoning: string;
|
|
48
|
+
connectionParameters: {} & {
|
|
49
|
+
[k: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
id?: string | undefined;
|
|
52
|
+
}>;
|
|
24
53
|
export declare function getAddNodeToolBase(nodeTypes: INodeTypeDescription[]): BuilderToolBase;
|
|
25
54
|
export declare function createAddNodeTool(nodeTypes: INodeTypeDescription[]): BuilderTool;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nodeCreationSchema = void 0;
|
|
3
|
+
exports.nodeCreationE2ESchema = exports.nodeCreationSchema = void 0;
|
|
4
4
|
exports.getAddNodeToolBase = getAddNodeToolBase;
|
|
5
5
|
exports.createAddNodeTool = createAddNodeTool;
|
|
6
6
|
const tools_1 = require("@langchain/core/tools");
|
|
@@ -13,8 +13,9 @@ const progress_1 = require("./helpers/progress");
|
|
|
13
13
|
const response_1 = require("./helpers/response");
|
|
14
14
|
const state_1 = require("./helpers/state");
|
|
15
15
|
const validation_1 = require("./helpers/validation");
|
|
16
|
-
|
|
16
|
+
const baseSchema = {
|
|
17
17
|
nodeType: zod_1.z.string().describe('The type of node to add (e.g., n8n-nodes-base.httpRequest)'),
|
|
18
|
+
nodeVersion: zod_1.z.number().describe('The exact node version'),
|
|
18
19
|
name: zod_1.z
|
|
19
20
|
.string()
|
|
20
21
|
.describe('A descriptive name for the node that clearly indicates its purpose in the workflow'),
|
|
@@ -25,12 +26,20 @@ exports.nodeCreationSchema = zod_1.z.object({
|
|
|
25
26
|
.object({})
|
|
26
27
|
.passthrough()
|
|
27
28
|
.describe('Parameters that affect node connections (e.g., mode: "insert" for Vector Store). Pass an empty object {} if no connection parameters are needed. Only connection-affecting parameters like mode, operation, resource, action, etc. are allowed.'),
|
|
29
|
+
};
|
|
30
|
+
exports.nodeCreationSchema = zod_1.z.object(baseSchema);
|
|
31
|
+
exports.nodeCreationE2ESchema = zod_1.z.object({
|
|
32
|
+
...baseSchema,
|
|
33
|
+
id: zod_1.z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Optional: A specific ID to use for this node. If not provided, a unique ID will be generated automatically. This is primarily used for testing purposes to ensure deterministic node IDs.'),
|
|
28
37
|
});
|
|
29
|
-
function createNode(nodeType, customName, existingNodes, nodeTypes, connectionParameters) {
|
|
38
|
+
function createNode(nodeType, typeVersion, customName, existingNodes, nodeTypes, connectionParameters, id) {
|
|
30
39
|
const baseName = customName ?? nodeType.defaults?.name ?? nodeType.displayName;
|
|
31
40
|
const uniqueName = (0, node_creation_utils_1.generateUniqueName)(baseName, existingNodes);
|
|
32
41
|
const position = (0, node_positioning_utils_1.calculateNodePosition)(existingNodes, (0, node_helpers_1.isSubNode)(nodeType), nodeTypes);
|
|
33
|
-
return (0, node_creation_utils_1.createNodeInstance)(nodeType, uniqueName, position, connectionParameters);
|
|
42
|
+
return (0, node_creation_utils_1.createNodeInstance)(nodeType, typeVersion, uniqueName, position, connectionParameters, id);
|
|
34
43
|
}
|
|
35
44
|
function buildResponseMessage(addedNode, nodeTypes) {
|
|
36
45
|
const nodeType = nodeTypes.find((nt) => nt.name === addedNode.type);
|
|
@@ -58,13 +67,22 @@ function createAddNodeTool(nodeTypes) {
|
|
|
58
67
|
const dynamicTool = (0, tools_1.tool)(async (input, config) => {
|
|
59
68
|
const reporter = (0, progress_1.createProgressReporter)(config, builderToolBase.toolName, builderToolBase.displayTitle, getCustomNodeTitle(input, nodeTypes));
|
|
60
69
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
let id;
|
|
71
|
+
let validatedInput;
|
|
72
|
+
if (process.env.E2E_TESTS) {
|
|
73
|
+
const e2eInput = exports.nodeCreationE2ESchema.parse(input);
|
|
74
|
+
id = e2eInput.id;
|
|
75
|
+
validatedInput = e2eInput;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
validatedInput = exports.nodeCreationSchema.parse(input);
|
|
79
|
+
}
|
|
80
|
+
const { nodeType, nodeVersion, name, connectionParametersReasoning, connectionParameters } = validatedInput;
|
|
63
81
|
reporter.start(validatedInput);
|
|
64
82
|
const state = (0, state_1.getWorkflowState)();
|
|
65
83
|
const workflow = (0, state_1.getCurrentWorkflow)(state);
|
|
66
84
|
reporter.progress(`Adding ${name} (${connectionParametersReasoning})`);
|
|
67
|
-
const nodeTypeDesc = (0, validation_1.findNodeType)(nodeType, nodeTypes);
|
|
85
|
+
const nodeTypeDesc = (0, validation_1.findNodeType)(nodeType, nodeVersion, nodeTypes);
|
|
68
86
|
if (!nodeTypeDesc) {
|
|
69
87
|
const nodeError = new errors_1.NodeTypeNotFoundError(nodeType);
|
|
70
88
|
const error = {
|
|
@@ -75,7 +93,7 @@ function createAddNodeTool(nodeTypes) {
|
|
|
75
93
|
reporter.error(error);
|
|
76
94
|
return (0, response_1.createErrorResponse)(config, error);
|
|
77
95
|
}
|
|
78
|
-
const newNode = createNode(nodeTypeDesc, name, workflow.nodes, nodeTypes, connectionParameters);
|
|
96
|
+
const newNode = createNode(nodeTypeDesc, nodeVersion, name, workflow.nodes, nodeTypes, connectionParameters, id);
|
|
79
97
|
const addedNodeInfo = {
|
|
80
98
|
id: newNode.id,
|
|
81
99
|
name: newNode.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-node.tool.js","sourceRoot":"","sources":["../../src/tools/add-node.tool.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"add-node.tool.js","sourceRoot":"","sources":["../../src/tools/add-node.tool.ts"],"names":[],"mappings":";;;AAqGA,gDAMC;AAKD,8CAsJC;AAtQD,iDAA6C;AAE7C,6BAAwB;AAIxB,sCAAmE;AACnE,qEAAqF;AACrF,2EAAuE;AACvE,wDAAkD;AAClD,iDAA4D;AAC5D,iDAAgF;AAChF,2CAA0F;AAC1F,qDAAoD;AAIpD,MAAM,UAAU,GAAG;IAClB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4DAA4D,CAAC;IAC3F,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IAC1D,IAAI,EAAE,OAAC;SACL,MAAM,EAAE;SACR,QAAQ,CAAC,oFAAoF,CAAC;IAChG,6BAA6B,EAAE,OAAC;SAC9B,MAAM,EAAE;SACR,QAAQ,CACR,gVAAgV,CAChV;IACF,oBAAoB,EAAE,OAAC;SACrB,MAAM,CAA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B,OAAO,IAAA,8BAAmB,EAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC,EACD;QACC,IAAI,EAAE,eAAe,CAAC,QAAQ;QAC9B,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qKA8BqJ;QAClK,MAAM,EAAE,0BAAkB;KAC1B,CACD,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,WAAW;QACjB,GAAG,eAAe;KAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BestPracticesDocument } from '../../types/best-practices';
|
|
2
|
+
export declare class ChatbotBestPractices implements BestPracticesDocument {
|
|
3
|
+
readonly technique: "chatbot";
|
|
4
|
+
readonly version = "1.0.0";
|
|
5
|
+
private readonly documentation;
|
|
6
|
+
getDocumentation(): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatbotBestPractices = void 0;
|
|
4
|
+
const categorization_1 = require("../../types/categorization");
|
|
5
|
+
class ChatbotBestPractices {
|
|
6
|
+
technique = categorization_1.WorkflowTechnique.CHATBOT;
|
|
7
|
+
version = '1.0.0';
|
|
8
|
+
documentation = `# Best Practices: Chatbot Workflows
|
|
9
|
+
|
|
10
|
+
## Workflow Design
|
|
11
|
+
|
|
12
|
+
Break chatbot logic into manageable steps and use error handling nodes (IF, Switch) with fallback mechanisms to manage unexpected inputs.
|
|
13
|
+
|
|
14
|
+
Most chatbots run through external platforms like Slack, Telegram, or WhatsApp rather than through the n8n chat interface - if the user
|
|
15
|
+
requests a service like this don't use the built in chat interface nodes. If the user mentions chatting but does not mention a service
|
|
16
|
+
then use the built in n8n chat node.
|
|
17
|
+
|
|
18
|
+
CRITICAL: The user may ask to be able to chat to a workflow as well as trigger it via some other method, for example scheduling information
|
|
19
|
+
gathering but also being able to chat with the agent - in scenarios like this the two separate workflows MUST be connected through shared memory,
|
|
20
|
+
vector stores, data storage, or direct connections.
|
|
21
|
+
|
|
22
|
+
Example pattern:
|
|
23
|
+
- Schedule Trigger → News Gathering Agent → [memory node via ai_memory]
|
|
24
|
+
- Chat Trigger → Chatbot Agent → [SAME memory node via ai_memory]
|
|
25
|
+
- Result: Both agents share conversation/context history, enabling the chatbot to discuss gathered news
|
|
26
|
+
|
|
27
|
+
For the chatbot always use the same chat node type as used for response. If Telegram has been requested trigger the chatbot via telegram AND
|
|
28
|
+
respond via telegram - do not mix chatbot interfaces.
|
|
29
|
+
|
|
30
|
+
## Context & Memory Management
|
|
31
|
+
|
|
32
|
+
Always utilise memory in chatbot agent nodes - providing context gives you full conversation history and more control over context.
|
|
33
|
+
Memory nodes enable the bot to handle follow-up questions by maintaining short-term conversation history.
|
|
34
|
+
|
|
35
|
+
Include information with the user prompt such as timestamp, user ID, or session metadata. This enriches context without relying solely on memory and user prompt.
|
|
36
|
+
|
|
37
|
+
If there are other agents involved in the workflow you should share memory between the chatbot and those other agents where it makes sense.
|
|
38
|
+
Connect the same memory node to multiple agents to enable data sharing and context continuity.
|
|
39
|
+
|
|
40
|
+
## Context Engineering & AI Agent Output
|
|
41
|
+
|
|
42
|
+
It can be beneficial to respond to the user as a tool of the chatbot agent rather than using the agent output - this allows the agent to loop/carry out multiple responses if necessary.
|
|
43
|
+
This will require adding a note to the system prompt for the agent to tell it to use the tool to respond to the user.
|
|
44
|
+
|
|
45
|
+
## Message Attribution
|
|
46
|
+
|
|
47
|
+
n8n chatbots often attach the attribution "n8n workflow" to messages by default - you must disable this setting which will
|
|
48
|
+
often be called "Append n8n Attribution" for nodes that support it, add this setting and set it to false.
|
|
49
|
+
|
|
50
|
+
## Recommended Nodes
|
|
51
|
+
|
|
52
|
+
### Chat Trigger (@n8n/n8n-nodes-langchain.chatTrigger)
|
|
53
|
+
|
|
54
|
+
Purpose: Entry point for user messages in n8n-hosted chat interfaces
|
|
55
|
+
|
|
56
|
+
Pitfalls:
|
|
57
|
+
|
|
58
|
+
- Most production chatbots use external platforms (Slack, Telegram) rather than n8n's chat interface
|
|
59
|
+
|
|
60
|
+
### AI Agent (@n8n/n8n-nodes-langchain.agent)
|
|
61
|
+
|
|
62
|
+
Purpose: Orchestrates logic, tool use, and LLM calls for intelligent responses
|
|
63
|
+
|
|
64
|
+
### Chat Model Nodes
|
|
65
|
+
|
|
66
|
+
- OpenAI Chat Model (@n8n/n8n-nodes-langchain.lmChatOpenAi)
|
|
67
|
+
- Google Gemini Chat Model (@n8n/n8n-nodes-langchain.lmChatGoogleGemini)
|
|
68
|
+
- xAI Grok Chat Model (@n8n/n8n-nodes-langchain.lmChatXAiGrok)
|
|
69
|
+
- DeepSeek Chat Model (@n8n/n8n-nodes-langchain.lmChatDeepSeek)
|
|
70
|
+
|
|
71
|
+
Purpose: Connect to LLMs for natural, context-aware responses
|
|
72
|
+
|
|
73
|
+
### Simple Memory (@n8n/n8n-nodes-langchain.memoryBufferWindow)
|
|
74
|
+
|
|
75
|
+
Purpose: Maintains short-term conversation history for context continuity
|
|
76
|
+
|
|
77
|
+
### HTTP Request (n8n-nodes-base.httpRequest)
|
|
78
|
+
|
|
79
|
+
Purpose: Fetches external data to enrich chatbot responses with real-time or organizational information
|
|
80
|
+
|
|
81
|
+
### Database Nodes & Google Sheets
|
|
82
|
+
|
|
83
|
+
- Postgres (n8n-nodes-base.postgres)
|
|
84
|
+
- MySQL (n8n-nodes-base.mySql)
|
|
85
|
+
- MongoDB (n8n-nodes-base.mongoDb)
|
|
86
|
+
- Google Sheets (n8n-nodes-base.googleSheets)
|
|
87
|
+
|
|
88
|
+
Purpose: Store conversation logs, retrieve structured data, or maintain user preferences
|
|
89
|
+
|
|
90
|
+
### IF / Switch
|
|
91
|
+
|
|
92
|
+
- If (n8n-nodes-base.if)
|
|
93
|
+
- Switch (n8n-nodes-base.switch)
|
|
94
|
+
|
|
95
|
+
Purpose: Conditional logic and error handling for routing messages or managing conversation state
|
|
96
|
+
|
|
97
|
+
### Integration Nodes
|
|
98
|
+
|
|
99
|
+
- Slack (n8n-nodes-base.slack)
|
|
100
|
+
- Telegram (n8n-nodes-base.telegram)
|
|
101
|
+
- WhatsApp Business Cloud (n8n-nodes-base.whatsApp)
|
|
102
|
+
- Discord (n8n-nodes-base.discord)
|
|
103
|
+
|
|
104
|
+
Purpose: Multi-channel support for deploying chatbots on popular messaging platforms
|
|
105
|
+
|
|
106
|
+
## Common Pitfalls to Avoid
|
|
107
|
+
|
|
108
|
+
### Leaving Chatbot Disconnected
|
|
109
|
+
|
|
110
|
+
When a workflow has multiple triggers (e.g., scheduled data collection + chatbot interaction), the chatbot MUST have access to the data
|
|
111
|
+
generated by the workflow. Connect the chatbot through shared memory, vector stores, data storage, or direct data flow connections.
|
|
112
|
+
`;
|
|
113
|
+
getDocumentation() {
|
|
114
|
+
return this.documentation;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.ChatbotBestPractices = ChatbotBestPractices;
|
|
118
|
+
//# sourceMappingURL=chatbot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatbot.js","sourceRoot":"","sources":["../../../src/tools/best-practices/chatbot.ts"],"names":[],"mappings":";;;AACA,2DAA2D;AAE3D,MAAa,oBAAoB;IACvB,SAAS,GAAG,kCAAiB,CAAC,OAAO,CAAC;IACtC,OAAO,GAAG,OAAO,CAAC;IAEV,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwGjC,CAAC;IAED,gBAAgB;QACf,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;CACD;AAjHD,oDAiHC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BestPracticesDocument } from '../../types/best-practices';
|
|
2
|
+
export declare class ContentGenerationBestPractices implements BestPracticesDocument {
|
|
3
|
+
readonly technique: "content_generation";
|
|
4
|
+
readonly version = "1.0.0";
|
|
5
|
+
private readonly documentation;
|
|
6
|
+
getDocumentation(): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentGenerationBestPractices = void 0;
|
|
4
|
+
const categorization_1 = require("../../types/categorization");
|
|
5
|
+
class ContentGenerationBestPractices {
|
|
6
|
+
technique = categorization_1.WorkflowTechnique.CONTENT_GENERATION;
|
|
7
|
+
version = '1.0.0';
|
|
8
|
+
documentation = `# Best Practices: Content Generation Workflows
|
|
9
|
+
|
|
10
|
+
## Workflow Design
|
|
11
|
+
|
|
12
|
+
Break complex tasks into sequential steps (e.g., generate text, create image, compose video) for modularity and easier troubleshooting.
|
|
13
|
+
|
|
14
|
+
## Content-Specific Guidance
|
|
15
|
+
|
|
16
|
+
For text generation, validate and sanitize input/output to avoid malformed data. When generating images, prefer binary data over URLs for uploads to avoid media type errors.
|
|
17
|
+
|
|
18
|
+
## Recommended Nodes
|
|
19
|
+
|
|
20
|
+
### OpenAI (@n8n/n8n-nodes-langchain.openAi)
|
|
21
|
+
|
|
22
|
+
Purpose: GPT-based text generation, DALL-E image generation, text-to-speech (TTS), and audio transcription
|
|
23
|
+
|
|
24
|
+
### xAI Grok Chat Model (@n8n/n8n-nodes-langchain.lmChatXAiGrok)
|
|
25
|
+
|
|
26
|
+
Purpose: Conversational AI and text generation
|
|
27
|
+
|
|
28
|
+
### Google Gemini Chat Model (@n8n/n8n-nodes-langchain.lmChatGoogleGemini)
|
|
29
|
+
|
|
30
|
+
Purpose: Image analysis and generation, video generation from text prompts, multimodal content creation
|
|
31
|
+
|
|
32
|
+
### ElevenLabs
|
|
33
|
+
|
|
34
|
+
Purpose: Natural-sounding AI voice generation
|
|
35
|
+
|
|
36
|
+
Note: Use HTTP Request node or a community node to integrate with ElevenLabs API
|
|
37
|
+
|
|
38
|
+
### HTTP Request (n8n-nodes-base.httpRequest)
|
|
39
|
+
|
|
40
|
+
Purpose: Integrating with other LLM and content generation APIs (e.g., Jasper, Writesonic, Anthropic, HuggingFace)
|
|
41
|
+
|
|
42
|
+
### Edit Image (n8n-nodes-base.editImage)
|
|
43
|
+
|
|
44
|
+
Purpose: Manipulating images - resize, crop, rotate, and format conversion
|
|
45
|
+
|
|
46
|
+
Pitfalls:
|
|
47
|
+
|
|
48
|
+
- Ensure input is valid binary image data
|
|
49
|
+
- Check output format compatibility with downstream nodes
|
|
50
|
+
|
|
51
|
+
### Markdown (n8n-nodes-base.markdown)
|
|
52
|
+
|
|
53
|
+
Purpose: Formatting and converting text to HTML or Markdown reports
|
|
54
|
+
|
|
55
|
+
### Facebook Graph API (n8n-nodes-base.facebookGraphApi)
|
|
56
|
+
|
|
57
|
+
Purpose: Uploading videos and images to Instagram and Facebook
|
|
58
|
+
|
|
59
|
+
Pitfalls:
|
|
60
|
+
|
|
61
|
+
- Use binary data fields rather than URLs for media uploads to prevent "media type" errors
|
|
62
|
+
- Verify page IDs and access tokens have correct permissions
|
|
63
|
+
|
|
64
|
+
### Wait (n8n-nodes-base.wait)
|
|
65
|
+
|
|
66
|
+
Purpose: Handling delays in video processing/uploading and respecting API rate limits
|
|
67
|
+
|
|
68
|
+
## Common Pitfalls to Avoid
|
|
69
|
+
|
|
70
|
+
Binary Data Handling: For media uploads, use binary fields rather than URLs to prevent "media type" errors, especially with Facebook and Instagram APIs. Download media to binary data first, then upload from binary rather than passing URLs.
|
|
71
|
+
|
|
72
|
+
Async Processing: For long-running content generation tasks (especially video), implement proper wait/polling mechanisms. Don't assume instant completion - many AI services process requests asynchronously.
|
|
73
|
+
`;
|
|
74
|
+
getDocumentation() {
|
|
75
|
+
return this.documentation;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ContentGenerationBestPractices = ContentGenerationBestPractices;
|
|
79
|
+
//# sourceMappingURL=content-generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-generation.js","sourceRoot":"","sources":["../../../src/tools/best-practices/content-generation.ts"],"names":[],"mappings":";;;AACA,2DAA2D;AAE3D,MAAa,8BAA8B;IACjC,SAAS,GAAG,kCAAiB,CAAC,kBAAkB,CAAC;IACjD,OAAO,GAAG,OAAO,CAAC;IAEV,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiEjC,CAAC;IAED,gBAAgB;QACf,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;CACD;AA1ED,wEA0EC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BestPracticesDocument } from '../../types/best-practices';
|
|
2
|
+
export declare class DataExtractionBestPractices implements BestPracticesDocument {
|
|
3
|
+
readonly technique: "data_extraction";
|
|
4
|
+
readonly version = "1.0.0";
|
|
5
|
+
private readonly documentation;
|
|
6
|
+
getDocumentation(): string;
|
|
7
|
+
}
|