n8n-nodes-ai-agent-langfuse 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -0
- package/dist/credentials/LangfuseApi.credentials.d.ts +10 -0
- package/dist/credentials/LangfuseApi.credentials.js +58 -0
- package/dist/credentials/LangfuseApi.credentials.js.map +1 -0
- package/dist/credentials/LangfuseApi.icon.svg +9 -0
- package/dist/nodes/AgentWithLangfuse/AgentWithLangfuse.icon.svg +7 -0
- package/dist/nodes/AgentWithLangfuse/AgentWithLangfuse.node.d.ts +5 -0
- package/dist/nodes/AgentWithLangfuse/AgentWithLangfuse.node.js +173 -0
- package/dist/nodes/AgentWithLangfuse/AgentWithLangfuse.node.js.map +1 -0
- package/dist/nodes/AgentWithLangfuse/AgentWithLangfuseDark.icon.svg +10 -0
- package/dist/nodes/AgentWithLangfuse/AgentWithLangfuseLight.icon.svg +10 -0
- package/dist/nodes/AgentWithLangfuse/V2/description.d.ts +4 -0
- package/dist/nodes/AgentWithLangfuse/V2/description.js +46 -0
- package/dist/nodes/AgentWithLangfuse/V2/description.js.map +1 -0
- package/dist/nodes/AgentWithLangfuse/V2/execute.d.ts +2 -0
- package/dist/nodes/AgentWithLangfuse/V2/execute.js +142 -0
- package/dist/nodes/AgentWithLangfuse/V2/execute.js.map +1 -0
- package/dist/nodes/AgentWithLangfuse/V2/utils.d.ts +2 -0
- package/dist/nodes/AgentWithLangfuse/V2/utils.js +70 -0
- package/dist/nodes/AgentWithLangfuse/V2/utils.js.map +1 -0
- package/dist/package.json +68 -0
- package/dist/src/types/types.d.ts +6 -0
- package/dist/src/types/types.js +3 -0
- package/dist/src/types/types.js.map +1 -0
- package/dist/src/utils/N8nOutputParser.d.ts +5 -0
- package/dist/src/utils/N8nOutputParser.js +14 -0
- package/dist/src/utils/N8nOutputParser.js.map +1 -0
- package/dist/src/utils/N8nTool.d.ts +10 -0
- package/dist/src/utils/N8nTool.js +86 -0
- package/dist/src/utils/N8nTool.js.map +1 -0
- package/dist/src/utils/common.d.ts +28 -0
- package/dist/src/utils/common.js +197 -0
- package/dist/src/utils/common.js.map +1 -0
- package/dist/src/utils/descriptions.d.ts +17 -0
- package/dist/src/utils/descriptions.js +135 -0
- package/dist/src/utils/descriptions.js.map +1 -0
- package/dist/src/utils/helpers.d.ts +24 -0
- package/dist/src/utils/helpers.js +221 -0
- package/dist/src/utils/helpers.js.map +1 -0
- package/dist/src/utils/options.d.ts +2 -0
- package/dist/src/utils/options.js +38 -0
- package/dist/src/utils/options.js.map +1 -0
- package/dist/src/utils/output_parsers/N8nStructuredOutputParser.d.ts +12 -0
- package/dist/src/utils/output_parsers/N8nStructuredOutputParser.js +105 -0
- package/dist/src/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -0
- package/dist/src/utils/prompt.d.ts +1 -0
- package/dist/src/utils/prompt.js +5 -0
- package/dist/src/utils/prompt.js.map +1 -0
- package/dist/src/utils/sharedFields.d.ts +8 -0
- package/dist/src/utils/sharedFields.js +150 -0
- package/dist/src/utils/sharedFields.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/index.js +0 -0
- package/package.json +68 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toolDescription = exports.textFromPreviousNode = exports.textInput = exports.promptTypeOptions = exports.inputSchemaField = exports.buildInputSchemaField = exports.jsonSchemaExampleField = exports.buildJsonSchemaExampleNotice = exports.buildJsonSchemaExampleField = exports.schemaTypeField = void 0;
|
|
4
|
+
exports.schemaTypeField = {
|
|
5
|
+
displayName: 'Schema Type',
|
|
6
|
+
name: 'schemaType',
|
|
7
|
+
type: 'options',
|
|
8
|
+
noDataExpression: true,
|
|
9
|
+
options: [
|
|
10
|
+
{
|
|
11
|
+
name: 'Generate From JSON Example',
|
|
12
|
+
value: 'fromJson',
|
|
13
|
+
description: 'Generate a schema from an example JSON object',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'Define using JSON Schema',
|
|
17
|
+
value: 'manual',
|
|
18
|
+
description: 'Define the JSON schema manually',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
default: 'fromJson',
|
|
22
|
+
description: 'How to specify the schema for the function',
|
|
23
|
+
};
|
|
24
|
+
const buildJsonSchemaExampleField = (props) => ({
|
|
25
|
+
displayName: 'JSON Example',
|
|
26
|
+
name: 'jsonSchemaExample',
|
|
27
|
+
type: 'json',
|
|
28
|
+
default: `{
|
|
29
|
+
"some_input": "some_value"
|
|
30
|
+
}`,
|
|
31
|
+
noDataExpression: true,
|
|
32
|
+
typeOptions: {
|
|
33
|
+
rows: 10,
|
|
34
|
+
},
|
|
35
|
+
displayOptions: {
|
|
36
|
+
show: {
|
|
37
|
+
...props === null || props === void 0 ? void 0 : props.showExtraProps,
|
|
38
|
+
schemaType: ['fromJson'],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
description: 'Example JSON object to use to generate the schema',
|
|
42
|
+
});
|
|
43
|
+
exports.buildJsonSchemaExampleField = buildJsonSchemaExampleField;
|
|
44
|
+
const buildJsonSchemaExampleNotice = (props) => ({
|
|
45
|
+
displayName: "All properties will be required. To make them optional, use the 'JSON Schema' schema type instead",
|
|
46
|
+
name: 'notice',
|
|
47
|
+
type: 'notice',
|
|
48
|
+
default: '',
|
|
49
|
+
displayOptions: {
|
|
50
|
+
show: {
|
|
51
|
+
...props === null || props === void 0 ? void 0 : props.showExtraProps,
|
|
52
|
+
schemaType: ['fromJson'],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
exports.buildJsonSchemaExampleNotice = buildJsonSchemaExampleNotice;
|
|
57
|
+
exports.jsonSchemaExampleField = (0, exports.buildJsonSchemaExampleField)();
|
|
58
|
+
const buildInputSchemaField = (props) => ({
|
|
59
|
+
displayName: 'Input Schema',
|
|
60
|
+
name: 'inputSchema',
|
|
61
|
+
type: 'json',
|
|
62
|
+
default: `{
|
|
63
|
+
"type": "object",
|
|
64
|
+
"properties": {
|
|
65
|
+
"some_input": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"description": "Some input to the function"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}`,
|
|
71
|
+
noDataExpression: false,
|
|
72
|
+
typeOptions: {
|
|
73
|
+
rows: 10,
|
|
74
|
+
},
|
|
75
|
+
displayOptions: {
|
|
76
|
+
show: {
|
|
77
|
+
...props === null || props === void 0 ? void 0 : props.showExtraProps,
|
|
78
|
+
schemaType: ['manual'],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
description: 'Schema to use for the function',
|
|
82
|
+
hint: 'Use <a target="_blank" href="https://json-schema.org/">JSON Schema</a> format (<a target="_blank" href="https://json-schema.org/learn/miscellaneous-examples.html">examples</a>). $refs syntax is currently not supported.',
|
|
83
|
+
});
|
|
84
|
+
exports.buildInputSchemaField = buildInputSchemaField;
|
|
85
|
+
exports.inputSchemaField = (0, exports.buildInputSchemaField)();
|
|
86
|
+
exports.promptTypeOptions = {
|
|
87
|
+
displayName: 'Source for Prompt (User Message)',
|
|
88
|
+
name: 'promptType',
|
|
89
|
+
type: 'options',
|
|
90
|
+
options: [
|
|
91
|
+
{
|
|
92
|
+
name: 'Connected Chat Trigger Node',
|
|
93
|
+
value: 'auto',
|
|
94
|
+
description: "Looks for an input field called 'chatInput' that is coming from a directly connected Chat Trigger",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Define below',
|
|
98
|
+
value: 'define',
|
|
99
|
+
description: 'Use an expression to reference data in previous nodes or enter static text',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
default: 'auto',
|
|
103
|
+
};
|
|
104
|
+
exports.textInput = {
|
|
105
|
+
displayName: 'Prompt (User Message)',
|
|
106
|
+
name: 'text',
|
|
107
|
+
type: 'string',
|
|
108
|
+
required: true,
|
|
109
|
+
default: '',
|
|
110
|
+
placeholder: 'e.g. Hello, how can you help me?',
|
|
111
|
+
typeOptions: {
|
|
112
|
+
rows: 2,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
exports.textFromPreviousNode = {
|
|
116
|
+
displayName: 'Prompt (User Message)',
|
|
117
|
+
name: 'text',
|
|
118
|
+
type: 'string',
|
|
119
|
+
required: true,
|
|
120
|
+
default: '={{ $json.chatInput }}',
|
|
121
|
+
typeOptions: {
|
|
122
|
+
rows: 2,
|
|
123
|
+
},
|
|
124
|
+
disabledOptions: { show: { promptType: ['auto'] } },
|
|
125
|
+
};
|
|
126
|
+
exports.toolDescription = {
|
|
127
|
+
displayName: 'Description',
|
|
128
|
+
name: 'toolDescription',
|
|
129
|
+
type: 'string',
|
|
130
|
+
default: 'AI Agent that can call other tools',
|
|
131
|
+
required: true,
|
|
132
|
+
typeOptions: { rows: 2 },
|
|
133
|
+
description: 'Explain to the LLM what this tool does, a good, specific description would allow LLMs to produce expected results much more often',
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=descriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptions.js","sourceRoot":"","sources":["../../../src/utils/descriptions.ts"],"names":[],"mappings":";;;AAEa,QAAA,eAAe,GAAoB;IAC5C,WAAW,EAAE,aAAa;IAC1B,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,SAAS;IACf,gBAAgB,EAAE,IAAI;IACtB,OAAO,EAAE;QACL;YACI,IAAI,EAAE,4BAA4B;YAClC,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,+CAA+C;SAC/D;QACD;YACI,IAAI,EAAE,0BAA0B;YAChC,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE,iCAAiC;SACjD;KACJ;IACD,OAAO,EAAE,UAAU;IACnB,WAAW,EAAE,4CAA4C;CAC5D,CAAC;AAMK,MAAM,2BAA2B,GAAG,CAAC,KAE3C,EAAmB,EAAE,CAAC,CAAC;IACpB,WAAW,EA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'@langchain/core/chat_history';
|
|
2
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
4
|
+
import type { Tool } from '@langchain/core/tools';
|
|
5
|
+
import type { BaseChatMemory } from 'langchain/memory';
|
|
6
|
+
import type { AiEvent, IDataObject, IExecuteFunctions, ISupplyDataFunctions, IWebhookFunctions } from 'n8n-workflow';
|
|
7
|
+
export declare function getMetadataFiltersValues(ctx: IExecuteFunctions | ISupplyDataFunctions, itemIndex: number): Record<string, never> | undefined;
|
|
8
|
+
export declare function isBaseChatMemory(obj: unknown): obj is BaseChatMemory;
|
|
9
|
+
export declare function isBaseChatMessageHistory(obj: unknown): obj is BaseChatMessageHistory;
|
|
10
|
+
export declare function isChatInstance(model: unknown): model is BaseChatModel;
|
|
11
|
+
export declare function isToolsInstance(model: unknown): model is Tool;
|
|
12
|
+
export declare function getPromptInputByType(options: {
|
|
13
|
+
ctx: IExecuteFunctions | ISupplyDataFunctions;
|
|
14
|
+
i: number;
|
|
15
|
+
promptTypeKey: string;
|
|
16
|
+
inputKey: string;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function getSessionId(ctx: ISupplyDataFunctions | IWebhookFunctions, itemIndex: number, selectorKey?: string, autoSelect?: string, customKey?: string): string;
|
|
19
|
+
export declare function logAiEvent(executeFunctions: IExecuteFunctions | ISupplyDataFunctions, event: AiEvent, data?: IDataObject): void;
|
|
20
|
+
export declare function serializeChatHistory(chatHistory: BaseMessage[]): string;
|
|
21
|
+
export declare function escapeSingleCurlyBrackets(text?: string): string | undefined;
|
|
22
|
+
export declare const getConnectedTools: (ctx: IExecuteFunctions | IWebhookFunctions | ISupplyDataFunctions, enforceUniqueNames: boolean, convertStructuredTool?: boolean, escapeCurlyBrackets?: boolean) => Promise<Tool<any>[]>;
|
|
23
|
+
export declare function unwrapNestedOutput(output: Record<string, unknown>): Record<string, unknown>;
|
|
24
|
+
export declare function hasLongSequentialRepeat(text: string, threshold?: number): boolean;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConnectedTools = void 0;
|
|
4
|
+
exports.getMetadataFiltersValues = getMetadataFiltersValues;
|
|
5
|
+
exports.isBaseChatMemory = isBaseChatMemory;
|
|
6
|
+
exports.isBaseChatMessageHistory = isBaseChatMessageHistory;
|
|
7
|
+
exports.isChatInstance = isChatInstance;
|
|
8
|
+
exports.isToolsInstance = isToolsInstance;
|
|
9
|
+
exports.getPromptInputByType = getPromptInputByType;
|
|
10
|
+
exports.getSessionId = getSessionId;
|
|
11
|
+
exports.logAiEvent = logAiEvent;
|
|
12
|
+
exports.serializeChatHistory = serializeChatHistory;
|
|
13
|
+
exports.escapeSingleCurlyBrackets = escapeSingleCurlyBrackets;
|
|
14
|
+
exports.unwrapNestedOutput = unwrapNestedOutput;
|
|
15
|
+
exports.hasLongSequentialRepeat = hasLongSequentialRepeat;
|
|
16
|
+
const agents_1 = require("langchain/agents");
|
|
17
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
18
|
+
const N8nTool_1 = require("./N8nTool");
|
|
19
|
+
function hasMethods(obj, ...methodNames) {
|
|
20
|
+
return methodNames.every((methodName) => typeof obj === 'object' &&
|
|
21
|
+
obj !== null &&
|
|
22
|
+
methodName in obj &&
|
|
23
|
+
typeof obj[methodName] === 'function');
|
|
24
|
+
}
|
|
25
|
+
function getMetadataFiltersValues(ctx, itemIndex) {
|
|
26
|
+
const options = ctx.getNodeParameter('options', itemIndex, {});
|
|
27
|
+
if (options.metadata) {
|
|
28
|
+
const { metadataValues: metadata } = options.metadata;
|
|
29
|
+
if (metadata.length > 0) {
|
|
30
|
+
return metadata.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (options.searchFilterJson) {
|
|
34
|
+
return ctx.getNodeParameter('options.searchFilterJson', itemIndex, '', {
|
|
35
|
+
ensureType: 'object',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function isBaseChatMemory(obj) {
|
|
41
|
+
return hasMethods(obj, 'loadMemoryVariables', 'saveContext');
|
|
42
|
+
}
|
|
43
|
+
function isBaseChatMessageHistory(obj) {
|
|
44
|
+
return hasMethods(obj, 'getMessages', 'addMessage');
|
|
45
|
+
}
|
|
46
|
+
function isChatInstance(model) {
|
|
47
|
+
var _a;
|
|
48
|
+
const namespace = (_a = model === null || model === void 0 ? void 0 : model.lc_namespace) !== null && _a !== void 0 ? _a : [];
|
|
49
|
+
return namespace.includes('chat_models');
|
|
50
|
+
}
|
|
51
|
+
function isToolsInstance(model) {
|
|
52
|
+
var _a;
|
|
53
|
+
const namespace = (_a = model === null || model === void 0 ? void 0 : model.lc_namespace) !== null && _a !== void 0 ? _a : [];
|
|
54
|
+
return namespace.includes('tools');
|
|
55
|
+
}
|
|
56
|
+
function getPromptInputByType(options) {
|
|
57
|
+
const { ctx, i, promptTypeKey, inputKey } = options;
|
|
58
|
+
const promptType = ctx.getNodeParameter(promptTypeKey, i, 'define');
|
|
59
|
+
let input;
|
|
60
|
+
if (promptType === 'auto') {
|
|
61
|
+
input = ctx.evaluateExpression('{{ $json["chatInput"] }}', i);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
input = ctx.getNodeParameter(inputKey, i);
|
|
65
|
+
}
|
|
66
|
+
if (input === undefined) {
|
|
67
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'No prompt specified', {
|
|
68
|
+
description: "Expected to find the prompt in an input field called 'chatInput' (this is what the chat trigger node outputs). To use something else, change the 'Prompt' parameter",
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return input;
|
|
72
|
+
}
|
|
73
|
+
function getSessionId(ctx, itemIndex, selectorKey = 'sessionIdType', autoSelect = 'fromInput', customKey = 'sessionKey') {
|
|
74
|
+
var _a;
|
|
75
|
+
let sessionId = '';
|
|
76
|
+
const selectorType = ctx.getNodeParameter(selectorKey, itemIndex);
|
|
77
|
+
if (selectorType === autoSelect) {
|
|
78
|
+
if ('getBodyData' in ctx) {
|
|
79
|
+
const bodyData = (_a = ctx.getBodyData()) !== null && _a !== void 0 ? _a : {};
|
|
80
|
+
sessionId = bodyData.sessionId;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
sessionId = ctx.evaluateExpression('{{ $json.sessionId }}', itemIndex);
|
|
84
|
+
if (!sessionId || sessionId === undefined) {
|
|
85
|
+
try {
|
|
86
|
+
const chatTrigger = ctx.getChatTrigger();
|
|
87
|
+
if (chatTrigger) {
|
|
88
|
+
sessionId = ctx.evaluateExpression(`{{ $('${chatTrigger.name}').first().json.sessionId }}`, itemIndex);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) { }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (sessionId === '' || sessionId === undefined) {
|
|
95
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'No session ID found', {
|
|
96
|
+
description: "Expected to find the session ID in an input field called 'sessionId' (this is what the chat trigger node outputs). To use something else, change the 'Session ID' parameter",
|
|
97
|
+
itemIndex,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
sessionId = ctx.getNodeParameter(customKey, itemIndex, '');
|
|
103
|
+
if (sessionId === '' || sessionId === undefined) {
|
|
104
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'Key parameter is empty', {
|
|
105
|
+
description: "Provide a key to use as session ID in the 'Key' parameter or use the 'Connected Chat Trigger Node' option to use the session ID from your Chat Trigger",
|
|
106
|
+
itemIndex,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return sessionId;
|
|
111
|
+
}
|
|
112
|
+
function logAiEvent(executeFunctions, event, data) {
|
|
113
|
+
try {
|
|
114
|
+
executeFunctions.logAiEvent(event, data ? (0, n8n_workflow_1.jsonStringify)(data) : undefined);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
executeFunctions.logger.debug(`Error logging AI event: ${event}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function serializeChatHistory(chatHistory) {
|
|
121
|
+
return chatHistory
|
|
122
|
+
.map((chatMessage) => {
|
|
123
|
+
if (chatMessage._getType() === 'human') {
|
|
124
|
+
return `Human: ${chatMessage.content}`;
|
|
125
|
+
}
|
|
126
|
+
else if (chatMessage._getType() === 'ai') {
|
|
127
|
+
return `Assistant: ${chatMessage.content}`;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
return `${chatMessage.content}`;
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
.join('\n');
|
|
134
|
+
}
|
|
135
|
+
function escapeSingleCurlyBrackets(text) {
|
|
136
|
+
if (text === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
let result = text;
|
|
139
|
+
result = result
|
|
140
|
+
.replace(/(?<!{){{{(?!{)/g, '{{{{')
|
|
141
|
+
.replace(/(?<!})}}}(?!})/g, '}}}}')
|
|
142
|
+
.replace(/(?<!{){(?!{)/g, '{{')
|
|
143
|
+
.replace(/(?<!})}(?!})/g, '}}');
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
const getConnectedTools = async (ctx, enforceUniqueNames, convertStructuredTool = true, escapeCurlyBrackets = false) => {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
const connectedTools = ((_a = (await ctx.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiTool, 0))) !== null && _a !== void 0 ? _a : []).flatMap((toolOrToolkit) => {
|
|
149
|
+
if (toolOrToolkit instanceof agents_1.Toolkit) {
|
|
150
|
+
return toolOrToolkit.getTools();
|
|
151
|
+
}
|
|
152
|
+
return toolOrToolkit;
|
|
153
|
+
});
|
|
154
|
+
if (!enforceUniqueNames)
|
|
155
|
+
return connectedTools;
|
|
156
|
+
const seenNames = new Set();
|
|
157
|
+
const finalTools = [];
|
|
158
|
+
for (const tool of connectedTools) {
|
|
159
|
+
const { name } = tool;
|
|
160
|
+
if (seenNames.has(name)) {
|
|
161
|
+
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), `You have multiple tools with the same name: '${name}', please rename them to avoid conflicts`);
|
|
162
|
+
}
|
|
163
|
+
seenNames.add(name);
|
|
164
|
+
if (escapeCurlyBrackets) {
|
|
165
|
+
tool.description = (_b = escapeSingleCurlyBrackets(tool.description)) !== null && _b !== void 0 ? _b : tool.description;
|
|
166
|
+
}
|
|
167
|
+
if (convertStructuredTool && tool instanceof N8nTool_1.N8nTool) {
|
|
168
|
+
finalTools.push(tool.asDynamicTool());
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
finalTools.push(tool);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return finalTools;
|
|
175
|
+
};
|
|
176
|
+
exports.getConnectedTools = getConnectedTools;
|
|
177
|
+
function unwrapNestedOutput(output) {
|
|
178
|
+
if ('output' in output &&
|
|
179
|
+
Object.keys(output).length === 1 &&
|
|
180
|
+
typeof output.output === 'object' &&
|
|
181
|
+
output.output !== null &&
|
|
182
|
+
'output' in output.output &&
|
|
183
|
+
Object.keys(output.output).length === 1) {
|
|
184
|
+
return output.output;
|
|
185
|
+
}
|
|
186
|
+
return output;
|
|
187
|
+
}
|
|
188
|
+
function hasLongSequentialRepeat(text, threshold = 1000) {
|
|
189
|
+
try {
|
|
190
|
+
if (text === null ||
|
|
191
|
+
typeof text !== 'string' ||
|
|
192
|
+
text.length === 0 ||
|
|
193
|
+
threshold <= 0 ||
|
|
194
|
+
text.length < threshold) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
const iterator = text[Symbol.iterator]();
|
|
198
|
+
let prev = iterator.next();
|
|
199
|
+
if (prev.done) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
let count = 1;
|
|
203
|
+
for (const char of iterator) {
|
|
204
|
+
if (char === prev.value) {
|
|
205
|
+
count++;
|
|
206
|
+
if (count >= threshold) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
count = 1;
|
|
212
|
+
prev = { value: char, done: false };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":";;;AA6BA,4DAyBC;AAED,4CAEC;AAED,4DAEC;AAED,wCAIC;AAED,0CAIC;AAED,oDAwBC;AAED,oCAqDC;AAED,gCAUC;AAED,oDAYC;AAED,8DAgBC;AAqDD,gDAaC;AASD,0DAsCC;AAnTD,6CAA2C;AAE3C,+CAAsF;AAStF,uCAAoC;AAGpC,SAAS,UAAU,CAAI,GAAY,EAAE,GAAG,WAAmC;IACvE,OAAO,WAAW,CAAC,KAAK,CACpB,CAAC,UAAU,EAAE,EAAE,CACX,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,UAAU,IAAI,GAAG;QACjB,OAAQ,GAAwC,CAAC,UAAU,CAAC,KAAK,UAAU,CAClF,CAAC;AACN,CAAC;AAED,SAAgB,wBAAwB,CACpC,GAA6C,EAC7C,SAAiB;IAEjB,MAAM,OAAO,GAAG,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IAE/D,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,QAK5C,CAAC;QACF,IAAI,QAAQ,CAAC,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AAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AASD,SAAgB,uBAAuB,CAAC,IAAY,EAAE,SAAS,GAAG,IAAI;IAClE,IAAI,CAAC;QAED,IACI,IAAI,KAAK,IAAI;YACb,OAAO,IAAI,KAAK,QAAQ;YACxB,IAAI,CAAC,MAAM,KAAK,CAAC;YACjB,SAAS,IAAI,CAAC;YACd,IAAI,CAAC,MAAM,GAAG,SAAS,EACzB,CAAC;YACC,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzC,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE3B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC1B,IAAI,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;gBACtB,KAAK,EAAE,CAAC;gBACR,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;oBACrB,OAAO,IAAI,CAAC;gBAChB,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,KAAK,GAAG,CAAC,CAAC;gBACV,IAAI,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;YACxC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAEb,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commonOptions = void 0;
|
|
4
|
+
const prompt_1 = require("./prompt");
|
|
5
|
+
exports.commonOptions = [
|
|
6
|
+
{
|
|
7
|
+
displayName: 'System Message',
|
|
8
|
+
name: 'systemMessage',
|
|
9
|
+
type: 'string',
|
|
10
|
+
default: prompt_1.SYSTEM_MESSAGE,
|
|
11
|
+
description: 'The message that will be sent to the agent before the conversation starts',
|
|
12
|
+
typeOptions: {
|
|
13
|
+
rows: 6,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
displayName: 'Max Iterations',
|
|
18
|
+
name: 'maxIterations',
|
|
19
|
+
type: 'number',
|
|
20
|
+
default: 10,
|
|
21
|
+
description: 'The maximum number of iterations the agent will run before stopping',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
displayName: 'Return Intermediate Steps',
|
|
25
|
+
name: 'returnIntermediateSteps',
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
default: false,
|
|
28
|
+
description: 'Whether or not the output should include intermediate steps the agent took',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
displayName: 'Automatically Passthrough Binary Images',
|
|
32
|
+
name: 'passthroughBinaryImages',
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
default: true,
|
|
35
|
+
description: 'Whether or not binary images should be automatically passed through to the agent as image type messages',
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/utils/options.ts"],"names":[],"mappings":";;;AAEA,qCAA0C;AAE7B,QAAA,aAAa,GAAsB;IAC5C;QACI,WAAW,EAAE,gBAAgB;QAC7B,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,uBAAc;QACvB,WAAW,EAAE,2EAA2E;QACxF,WAAW,EAAE;YACT,IAAI,EAAE,CAAC;SACV;KACJ;IACD;QACI,WAAW,EAAE,gBAAgB;QAC7B,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,qEAAqE;KACrF;IACD;QACI,WAAW,EAAE,2BAA2B;QACxC,IAAI,EAAE,yBAAyB;QAC/B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,4EAA4E;KAC5F;IACD;QACI,WAAW,EAAE,yCAAyC;QACtD,IAAI,EAAE,yBAAyB;QAC/B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,IAAI;QACb,WAAW,EACP,yGAAyG;KAChH;CACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Callbacks } from '@langchain/core/callbacks/manager';
|
|
2
|
+
import { StructuredOutputParser } from 'langchain/output_parsers';
|
|
3
|
+
import type { ISupplyDataFunctions } from 'n8n-workflow';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare class N8nStructuredOutputParser extends StructuredOutputParser<any> {
|
|
6
|
+
private context;
|
|
7
|
+
constructor(context: ISupplyDataFunctions, zodSchema: z.ZodSchema<object>);
|
|
8
|
+
lc_namespace: string[];
|
|
9
|
+
parse(text: string, _callbacks?: Callbacks, errorMapper?: (error: Error) => Error): Promise<object>;
|
|
10
|
+
static fromZodJsonSchema(zodSchema: z.ZodSchema<object>, nodeVersion: number, context: ISupplyDataFunctions): Promise<N8nStructuredOutputParser>;
|
|
11
|
+
getSchema(): any;
|
|
12
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.N8nStructuredOutputParser = void 0;
|
|
7
|
+
const output_parsers_1 = require("langchain/output_parsers");
|
|
8
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
9
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
12
|
+
const STRUCTURED_OUTPUT_KEY = '__structured__output';
|
|
13
|
+
const STRUCTURED_OUTPUT_OBJECT_KEY = '__structured__output__object';
|
|
14
|
+
const STRUCTURED_OUTPUT_ARRAY_KEY = '__structured__output__array';
|
|
15
|
+
class N8nStructuredOutputParser extends output_parsers_1.StructuredOutputParser {
|
|
16
|
+
constructor(context, zodSchema) {
|
|
17
|
+
super(zodSchema);
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.lc_namespace = ['langchain', 'output_parsers', 'structured'];
|
|
20
|
+
}
|
|
21
|
+
async parse(text, _callbacks, errorMapper) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
23
|
+
const { index } = this.context.addInputData(n8n_workflow_1.NodeConnectionTypes.AiOutputParser, [
|
|
24
|
+
[{ json: { action: 'parse', text } }],
|
|
25
|
+
]);
|
|
26
|
+
try {
|
|
27
|
+
const jsonString = text.includes('```') ? text.split(/```(?:json)?/)[1] : text;
|
|
28
|
+
const json = JSON.parse(jsonString.trim());
|
|
29
|
+
const parsed = await this.schema.parseAsync(json);
|
|
30
|
+
let result = ((_c = (_b = (_a = (0, get_1.default)(parsed, [STRUCTURED_OUTPUT_KEY, STRUCTURED_OUTPUT_OBJECT_KEY])) !== null && _a !== void 0 ? _a : (0, get_1.default)(parsed, [STRUCTURED_OUTPUT_KEY, STRUCTURED_OUTPUT_ARRAY_KEY])) !== null && _b !== void 0 ? _b : (0, get_1.default)(parsed, STRUCTURED_OUTPUT_KEY)) !== null && _c !== void 0 ? _c : parsed);
|
|
31
|
+
result = (0, helpers_1.unwrapNestedOutput)(result);
|
|
32
|
+
(0, helpers_1.logAiEvent)(this.context, 'ai-output-parsed', { text, response: result });
|
|
33
|
+
this.context.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiOutputParser, index, [
|
|
34
|
+
[{ json: { action: 'parse', response: result } }],
|
|
35
|
+
]);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
const nodeError = new n8n_workflow_1.NodeOperationError(this.context.getNode(), "Model output doesn't fit required format", {
|
|
40
|
+
description: "To continue the execution when this happens, change the 'On Error' parameter in the root node's settings",
|
|
41
|
+
});
|
|
42
|
+
if (e instanceof SyntaxError) {
|
|
43
|
+
nodeError.context.outputParserFailReason = 'Invalid JSON in model output';
|
|
44
|
+
}
|
|
45
|
+
else if ((typeof text === 'string' && text.trim() === '{}') ||
|
|
46
|
+
(e instanceof zod_1.z.ZodError &&
|
|
47
|
+
((_d = e.issues) === null || _d === void 0 ? void 0 : _d[0]) &&
|
|
48
|
+
((_e = e.issues) === null || _e === void 0 ? void 0 : _e[0].code) === 'invalid_type' &&
|
|
49
|
+
((_g = (_f = e.issues) === null || _f === void 0 ? void 0 : _f[0].path) === null || _g === void 0 ? void 0 : _g[0]) === 'output' &&
|
|
50
|
+
((_h = e.issues) === null || _h === void 0 ? void 0 : _h[0].expected) === 'object' &&
|
|
51
|
+
((_j = e.issues) === null || _j === void 0 ? void 0 : _j[0].received) === 'undefined')) {
|
|
52
|
+
nodeError.context.outputParserFailReason = 'Model output wrapper is an empty object';
|
|
53
|
+
}
|
|
54
|
+
else if (e instanceof zod_1.z.ZodError) {
|
|
55
|
+
nodeError.context.outputParserFailReason =
|
|
56
|
+
'Model output does not match the expected schema';
|
|
57
|
+
}
|
|
58
|
+
(0, helpers_1.logAiEvent)(this.context, 'ai-output-parsed', {
|
|
59
|
+
text,
|
|
60
|
+
response: (_k = e.message) !== null && _k !== void 0 ? _k : e,
|
|
61
|
+
});
|
|
62
|
+
this.context.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiOutputParser, index, nodeError);
|
|
63
|
+
if (errorMapper) {
|
|
64
|
+
throw errorMapper(e);
|
|
65
|
+
}
|
|
66
|
+
throw nodeError;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static async fromZodJsonSchema(zodSchema, nodeVersion, context) {
|
|
70
|
+
let returnSchema;
|
|
71
|
+
if (nodeVersion === 1) {
|
|
72
|
+
returnSchema = zod_1.z.object({
|
|
73
|
+
[STRUCTURED_OUTPUT_KEY]: zod_1.z
|
|
74
|
+
.object({
|
|
75
|
+
[STRUCTURED_OUTPUT_OBJECT_KEY]: zodSchema.optional(),
|
|
76
|
+
[STRUCTURED_OUTPUT_ARRAY_KEY]: zod_1.z.array(zodSchema).optional(),
|
|
77
|
+
})
|
|
78
|
+
.describe(`Wrapper around the output data. It can only contain ${STRUCTURED_OUTPUT_OBJECT_KEY} or ${STRUCTURED_OUTPUT_ARRAY_KEY} but never both.`)
|
|
79
|
+
.refine((data) => {
|
|
80
|
+
return (Boolean(data[STRUCTURED_OUTPUT_OBJECT_KEY]) !==
|
|
81
|
+
Boolean(data[STRUCTURED_OUTPUT_ARRAY_KEY]));
|
|
82
|
+
}, {
|
|
83
|
+
message: 'One and only one of __structured__output__object and __structured__output__array should be present.',
|
|
84
|
+
path: [STRUCTURED_OUTPUT_KEY],
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else if (nodeVersion < 1.3) {
|
|
89
|
+
returnSchema = zod_1.z.object({
|
|
90
|
+
output: zodSchema.optional(),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
returnSchema = zod_1.z.object({
|
|
95
|
+
output: zodSchema,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return new N8nStructuredOutputParser(context, returnSchema);
|
|
99
|
+
}
|
|
100
|
+
getSchema() {
|
|
101
|
+
return this.schema;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.N8nStructuredOutputParser = N8nStructuredOutputParser;
|
|
105
|
+
//# sourceMappingURL=N8nStructuredOutputParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"N8nStructuredOutputParser.js","sourceRoot":"","sources":["../../../../src/utils/output_parsers/N8nStructuredOutputParser.ts"],"names":[],"mapp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CAAC,4BAA4B,CAAC,CAAC;wBAC3C,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAC1C,CAAC;gBACH,CAAC,EACD;oBACC,OAAO,EACN,qGAAqG;oBACtG,IAAI,EAAE,CAAC,qBAAqB,CAAC;iBAC7B,CACD;aACF,CAAC,CAAC;QACJ,CAAC;aAAM,IAAI,WAAW,GAAG,GAAG,EAAE,CAAC;YAC9B,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,SAAS,CAAC,QAAQ,EAAE;aAC5B,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,SAAS;aACjB,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,yBAAyB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC7D,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AAhID,8DAgIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SYSTEM_MESSAGE = "You are a helpful assistant";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/utils/prompt.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NodeConnectionTypes } from 'n8n-workflow';
|
|
2
|
+
import type { IDisplayOptions, INodeProperties } from 'n8n-workflow';
|
|
3
|
+
export declare const metadataFilterField: INodeProperties;
|
|
4
|
+
export declare function getTemplateNoticeField(templateId: number): INodeProperties;
|
|
5
|
+
export declare function getBatchingOptionFields(displayOptions: IDisplayOptions | undefined, defaultBatchSize?: number): INodeProperties;
|
|
6
|
+
type AllowedConnectionTypes = typeof NodeConnectionTypes.AiAgent | typeof NodeConnectionTypes.AiChain | typeof NodeConnectionTypes.AiDocument | typeof NodeConnectionTypes.AiVectorStore | typeof NodeConnectionTypes.AiRetriever;
|
|
7
|
+
export declare function getConnectionHintNoticeField(connectionTypes: AllowedConnectionTypes[]): INodeProperties;
|
|
8
|
+
export {};
|