n8n-nodes-simple 2.4.13 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nodes/shared/api/errors.d.ts +45 -0
- package/dist/nodes/shared/api/errors.js +134 -0
- package/dist/nodes/shared/api/errors.js.map +1 -0
- package/dist/nodes/shared/config/parameters.d.ts +1 -1
- package/dist/nodes/shared/config/parameters.js +1 -1
- package/dist/nodes/shared/config/parameters.js.map +1 -1
- package/dist/nodes/shared/config/properties/options.js +17 -46
- package/dist/nodes/shared/config/properties/options.js.map +1 -1
- package/dist/nodes/shared/config/properties/output.js +22 -34
- package/dist/nodes/shared/config/properties/output.js.map +1 -1
- package/dist/nodes/shared/core/execution/errors.d.ts +14 -0
- package/dist/nodes/shared/core/execution/errors.js +65 -0
- package/dist/nodes/shared/core/execution/errors.js.map +1 -0
- package/dist/nodes/shared/core/execution/executor.d.ts +1 -2
- package/dist/nodes/shared/core/execution/executor.js +73 -75
- package/dist/nodes/shared/core/execution/executor.js.map +1 -1
- package/dist/nodes/shared/core/execution/messageOperation.js +1 -1
- package/dist/nodes/shared/core/execution/messageOperation.js.map +1 -1
- package/dist/nodes/shared/core/execution/outputData.d.ts +1 -1
- package/dist/nodes/shared/core/execution/outputData.js +16 -31
- package/dist/nodes/shared/core/execution/outputData.js.map +1 -1
- package/dist/nodes/shared/core/execution/retryHandler.d.ts +9 -0
- package/dist/nodes/shared/core/execution/retryHandler.js +89 -0
- package/dist/nodes/shared/core/execution/retryHandler.js.map +1 -0
- package/dist/nodes/shared/core/execution/router.js +4 -24
- package/dist/nodes/shared/core/execution/router.js.map +1 -1
- package/dist/nodes/shared/core/request/body.d.ts +1 -1
- package/dist/nodes/shared/core/request/body.js +1 -7
- package/dist/nodes/shared/core/request/body.js.map +1 -1
- package/dist/nodes/shared/core/request/validation.d.ts +11 -0
- package/dist/nodes/shared/core/request/validation.js +47 -0
- package/dist/nodes/shared/core/request/validation.js.map +1 -0
- package/dist/nodes/shared/core/request/visualEditor.js +17 -3
- package/dist/nodes/shared/core/request/visualEditor.js.map +1 -1
- package/dist/nodes/shared/core/tools/executor.d.ts +2 -1
- package/dist/nodes/shared/core/tools/executor.js +7 -4
- package/dist/nodes/shared/core/tools/executor.js.map +1 -1
- package/dist/nodes/shared/core/tools/setup.d.ts +1 -1
- package/dist/nodes/shared/core/tools/setup.js +1 -1
- package/dist/nodes/shared/core/tools/setup.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,102 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runModel = runModel;
|
|
4
|
-
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
5
|
const structuredOutput_1 = require("../request/structuredOutput");
|
|
6
6
|
const setup_1 = require("../tools/setup");
|
|
7
7
|
const body_1 = require("../request/body");
|
|
8
8
|
const executor_1 = require("../tools/executor");
|
|
9
9
|
const outputData_1 = require("./outputData");
|
|
10
10
|
const io_1 = require("../memory/io");
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const validation_1 = require("../request/validation");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
const retryHandler_1 = require("./retryHandler");
|
|
14
|
+
async function runModel(executeFunctions, params, messages, index, modelToUse, memory) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
13
16
|
let responseFormat = (0, structuredOutput_1.prepareResponseFormatField)(params.responseFormat, params.outputJsonSchemaDefinition, params.structuredOutputName, params.structuredOutputDescription, params.structuredOutputProperties, params.structuredOutputIsArray, params.structuredOutputArrayName, params.structuredOutputArrayDescription);
|
|
14
17
|
const { tools, invokableTools, tool_choice, structuredOutputTool } = await (0, setup_1.prepareTools)(executeFunctions, params.structuredOutputToolsMode, params.maxToolsIterations, responseFormat);
|
|
15
18
|
if (params.structuredOutputToolsMode) {
|
|
16
19
|
responseFormat = undefined;
|
|
17
20
|
}
|
|
18
21
|
;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
? (_a = response === null || response === void 0 ? void 0 : response.choices[0]) === null || _a === void 0 ? void 0 : _a.message.content
|
|
26
|
-
: JSON.parse((_b = response === null || response === void 0 ? void 0 : response.choices[0]) === null || _b === void 0 ? void 0 : _b.message.content));
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
30
|
-
const showValue = (val) => {
|
|
31
|
-
if (val === null)
|
|
32
|
-
return 'null';
|
|
33
|
-
if (val === undefined)
|
|
34
|
-
return 'undefined';
|
|
35
|
-
if (val === '')
|
|
36
|
-
return '<empty string>';
|
|
37
|
-
return String(val);
|
|
38
|
-
};
|
|
39
|
-
let detailedError = `JSON parse error: ${errorMessage}.`;
|
|
40
|
-
detailedError += ` | Assistant message content: ${showValue((_e = (_d = (_c = response === null || response === void 0 ? void 0 : response.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.content)}`;
|
|
41
|
-
detailedError += ` | Structured output tool response: ${showValue(structuredOutputToolResponse)}`;
|
|
42
|
-
detailedError += ` | Full response: ${JSON.stringify(response, null, 2)}`;
|
|
43
|
-
throw new Error(detailedError);
|
|
44
|
-
}
|
|
45
|
-
const outputData = await (0, outputData_1.prepareOutputData)(response, output, messages, params.addToOutput, executeFunctions, index, body, primaryError);
|
|
46
|
-
if (memory) {
|
|
47
|
-
await (0, io_1.saveToMemory)(messages, output, params.saveToolCallsInChatMemory, memory);
|
|
48
|
-
}
|
|
49
|
-
return outputData;
|
|
50
|
-
}
|
|
51
|
-
function extractErrorInfo(error) {
|
|
52
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
-
const description = error.description;
|
|
54
|
-
const requestBody = error.requestBody;
|
|
55
|
-
const httpCode = error.httpCode;
|
|
56
|
-
return { message, description, requestBody, httpCode };
|
|
57
|
-
}
|
|
58
|
-
async function runModelWithFallback(executeFunctions, params, messages, index, memory) {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
try {
|
|
61
|
-
const item = await runModel(executeFunctions, params, messages, index, params.model, memory);
|
|
62
|
-
if (!item || item.length === 0) {
|
|
63
|
-
throw new Error(`Model returned no data: ${JSON.stringify(item)}`);
|
|
22
|
+
const shouldValidate = params.tenacityMaxRetries > 0 &&
|
|
23
|
+
(params.responseFormat === 'structuredOutputSchema' || params.responseFormat === 'structuredOutputVisual');
|
|
24
|
+
let validationSchema;
|
|
25
|
+
if (shouldValidate) {
|
|
26
|
+
if (params.structuredOutputToolsMode && structuredOutputTool) {
|
|
27
|
+
validationSchema = (_a = structuredOutputTool.function) === null || _a === void 0 ? void 0 : _a.parameters;
|
|
64
28
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
29
|
+
else if (responseFormat === null || responseFormat === void 0 ? void 0 : responseFormat.json_schema) {
|
|
30
|
+
validationSchema = (_b = responseFormat.json_schema) === null || _b === void 0 ? void 0 : _b.schema;
|
|
67
31
|
}
|
|
68
|
-
return item;
|
|
69
32
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
33
|
+
let retryState = {
|
|
34
|
+
retriesRemaining: params.tenacityMaxRetries,
|
|
35
|
+
attemptNumber: 1,
|
|
36
|
+
};
|
|
37
|
+
let messagesBeforeRetries = messages.length;
|
|
38
|
+
let currentIteration = 1;
|
|
39
|
+
while (true) {
|
|
40
|
+
const body = (0, body_1.prepareRequestBody)(modelToUse, messages, tools, tool_choice, responseFormat, params.options, params.customParameters);
|
|
41
|
+
const { response, structuredOutputToolResponse, finalIteration } = await (0, executor_1.processToolCalls)(executeFunctions, body, messages, invokableTools, params.maxToolsIterations, structuredOutputTool, params.abortSignal, currentIteration);
|
|
42
|
+
currentIteration = finalIteration;
|
|
43
|
+
body.messages = messages;
|
|
44
|
+
if (retryState.attemptNumber === 1) {
|
|
45
|
+
messagesBeforeRetries = messages.length;
|
|
46
|
+
}
|
|
47
|
+
let output;
|
|
48
|
+
let parseError = null;
|
|
49
|
+
try {
|
|
50
|
+
output = JSON.parse(structuredOutputToolResponse)
|
|
51
|
+
|| (params.responseFormat === "plainText"
|
|
52
|
+
? (_c = response === null || response === void 0 ? void 0 : response.choices[0]) === null || _c === void 0 ? void 0 : _c.message.content
|
|
53
|
+
: JSON.parse((_d = response === null || response === void 0 ? void 0 : response.choices[0]) === null || _d === void 0 ? void 0 : _d.message.content));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const simpleErrorMessage = error instanceof Error ? error.message : String(error);
|
|
57
|
+
if (shouldValidate && retryState.retriesRemaining > 0) {
|
|
58
|
+
parseError = simpleErrorMessage;
|
|
76
59
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
else {
|
|
61
|
+
const errorData = (0, errors_1.buildDetailedParseError)(simpleErrorMessage, response, structuredOutputToolResponse, body);
|
|
62
|
+
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), errorData.message, {
|
|
63
|
+
description: errorData.description,
|
|
64
|
+
itemIndex: index,
|
|
65
|
+
});
|
|
80
66
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
67
|
+
}
|
|
68
|
+
if (parseError) {
|
|
69
|
+
const shouldRetry = await (0, retryHandler_1.handleParseError)(parseError, response, messages, retryState, params.structuredOutputToolsMode, structuredOutputTool, params.structuredOutputName, tools);
|
|
70
|
+
if (shouldRetry) {
|
|
71
|
+
retryState = (0, retryHandler_1.updateRetryState)(retryState);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (shouldValidate) {
|
|
76
|
+
const validationResult = (0, validation_1.validateStructuredOutput)(validationSchema, output);
|
|
77
|
+
if (!validationResult.isValid) {
|
|
78
|
+
const validationError = validationResult.error || 'Unknown validation error';
|
|
79
|
+
const shouldRetry = await (0, retryHandler_1.handleValidationError)(validationError, output, response, messages, retryState, params.structuredOutputToolsMode, structuredOutputTool, params.structuredOutputName);
|
|
80
|
+
if (shouldRetry) {
|
|
81
|
+
retryState = (0, retryHandler_1.updateRetryState)(retryState);
|
|
82
|
+
continue;
|
|
91
83
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
else {
|
|
85
|
+
const errorData = (0, errors_1.buildValidationError)(params.tenacityMaxRetries, validationError, output, body, response);
|
|
86
|
+
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), errorData.message, {
|
|
87
|
+
description: errorData.description,
|
|
88
|
+
itemIndex: index,
|
|
89
|
+
});
|
|
95
90
|
}
|
|
96
|
-
throw combinedError;
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
|
-
|
|
93
|
+
const outputData = await (0, outputData_1.prepareOutputData)(response, output, messages, messagesBeforeRetries, params.addToOutput, executeFunctions, index, body);
|
|
94
|
+
if (memory) {
|
|
95
|
+
await (0, io_1.saveToMemory)(messages, output, params.saveToolCallsInChatMemory, memory);
|
|
96
|
+
}
|
|
97
|
+
return outputData;
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
//# sourceMappingURL=executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/executor.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/executor.ts"],"names":[],"mappings":";;AAiBA,4BAsNC;AAtOD,+CAAkD;AAGlD,kEAAyE;AACzE,0CAA8C;AAC9C,0CAAqD;AACrD,gDAAqD;AACrD,6CAAiD;AACjD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e,EACf,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,CAAC,yBAAyB,EAChC,oBAAoB,EACpB,MAAM,CAAC,oBAAoB,CAC3B,CAAC;gBAEF,IAAI,WAAW,EAAE,CAAC;oBAEjB,UAAU,GAAG,IAAA,+BAAgB,EAAC,UAAU,CAAC,CAAC;oBAC1C,SAAS;gBACV,CAAC;qBAAM,CAAC;oBAEP,MAAM,SAAS,GAAG,IAAA,6BAAoB,EACrC,MAAM,CAAC,kBAAkB,EACzB,eAAe,EACf,MAAM,EACN,IAAI,EACJ,QAAQ,CACR,CAAC;oBACF,MAAM,IAAI,iCAAkB,CAC3B,gBAAgB,CAAC,OAAO,EAAE,EAC1B,SAAS,CAAC,OAAO,EACjB;wBACC,WAAW,EAAE,SAAS,CAAC,WAAW;wBAClC,SAAS,EAAE,KAAK;qBAChB,CACD,CAAC;gBACH,CAAC;YACF,CAAC;QACF,CAAC;QAID,MAAM,UAAU,GAAG,MAAM,IAAA,8BAAiB,EACzC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,qBAAqB,EACrB,MAAM,CAAC,WAAW,EAClB,gBAAgB,EAChB,KAAK,EACL,IAAI,CACJ,CAAC;QAGF,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,IAAA,iBAAY,EACjB,QAAQ,EACR,MAAM,EACN,MAAM,CAAC,yBAAyB,EAChC,MAAM,CACN,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC;AACF,CAAC"}
|
|
@@ -9,6 +9,6 @@ async function execute(i) {
|
|
|
9
9
|
const params = (0, parameters_1.extractParameters)(this, i);
|
|
10
10
|
const memory = await (0, io_1.getOptionalMemory)(this);
|
|
11
11
|
const messages = await (0, chatHistory_1.unpackChatHistoryAndMemory)(params.rawMessagesToSend, params.loadToolCallsFromChatMemory, memory);
|
|
12
|
-
return await (0, executor_1.
|
|
12
|
+
return await (0, executor_1.runModel)(this, params, messages, i, params.model, memory);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=messageOperation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageOperation.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/messageOperation.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"messageOperation.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/messageOperation.ts"],"names":[],"mappings":";;AAUA,0BA0BC;AAlCD,wDAA4D;AAC5D,qCAAiD;AACjD,yDAAqE;AACrE,yCAAsC;AAK/B,KAAK,UAAU,OAAO,CAE5B,CAAS;IAGT,MAAM,MAAM,GAAG,IAAA,8BAAiB,EAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAG1C,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAiB,EAAC,IAAI,CAAC,CAAC;IAG7C,MAAM,QAAQ,GAAG,MAAM,IAAA,wCAA0B,EAChD,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,2BAA2B,EAClC,MAAM,CACN,CAAC;IAGF,OAAO,MAAM,IAAA,mBAAQ,EACpB,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,CAAC,EACD,MAAM,CAAC,KAAK,EACZ,MAAM,CACN,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { IExecuteFunctions, INodeExecutionData, IDataObject } from 'n8n-workflow';
|
|
2
2
|
import type { ChatCompletion } from '../../api/types';
|
|
3
|
-
export declare function prepareOutputData(response: ChatCompletion, output: any, messages: IDataObject[], addToOutput: string[], executeFunctions: IExecuteFunctions, index: number, body: IDataObject
|
|
3
|
+
export declare function prepareOutputData(response: ChatCompletion, output: any, messages: IDataObject[], messagesBeforeRetries: number, addToOutput: string[], executeFunctions: IExecuteFunctions, index: number, body: IDataObject): Promise<INodeExecutionData[]>;
|
|
4
4
|
export declare function reorderOutputFields(outputData: INodeExecutionData[]): void;
|
|
@@ -2,56 +2,42 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepareOutputData = prepareOutputData;
|
|
4
4
|
exports.reorderOutputFields = reorderOutputFields;
|
|
5
|
-
|
|
6
|
-
async function prepareOutputData(response, output, messages, addToOutput, executeFunctions, index, body, primaryError) {
|
|
5
|
+
async function prepareOutputData(response, output, messages, messagesBeforeRetries, addToOutput, executeFunctions, index, body) {
|
|
7
6
|
const outputData = [];
|
|
8
7
|
outputData.push({ json: { output: output }, pairedItem: { item: index } });
|
|
9
|
-
if (primaryError) {
|
|
10
|
-
outputData.forEach((item) => {
|
|
11
|
-
item.json.error = primaryError;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
8
|
if (addToOutput.includes('fullResponse')) {
|
|
15
9
|
outputData.forEach((item) => {
|
|
16
10
|
item.json.response = response;
|
|
17
11
|
});
|
|
18
12
|
}
|
|
19
|
-
const newMessages = (i => i === -1 ? [] : messages.slice(i + 1))(messages.map(o => o.role).lastIndexOf("user"));
|
|
20
|
-
if (addToOutput.includes('toolCalls')) {
|
|
21
|
-
outputData.forEach((item) => {
|
|
22
|
-
item.json.tool_calls = (0, messageExtractor_1.extractToolMessages)(newMessages);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
13
|
if (addToOutput.includes('chatHistory')) {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
const includeInChatHistory = executeFunctions.getNodeParameter('includeInChatHistory', index, []);
|
|
15
|
+
const includeToolCalls = includeInChatHistory.includes('toolCalls');
|
|
16
|
+
const includeSystemMessages = includeInChatHistory.includes('systemMessages');
|
|
17
|
+
const includeReasoning = includeInChatHistory.includes('reasoning');
|
|
18
|
+
let chatHistoryMessages = structuredClone(messages.slice(0, messagesBeforeRetries));
|
|
19
|
+
if (!includeToolCalls) {
|
|
31
20
|
chatHistoryMessages = chatHistoryMessages
|
|
32
21
|
.filter((msg) => msg.content !== null && msg.content !== '' && msg.role !== 'tool')
|
|
33
22
|
.map(({ role, content }) => ({ role, content }));
|
|
34
23
|
}
|
|
35
|
-
if (!
|
|
24
|
+
if (!includeSystemMessages) {
|
|
36
25
|
chatHistoryMessages = chatHistoryMessages.filter((msg) => msg.role !== 'system');
|
|
37
26
|
}
|
|
38
27
|
const finalMessage = response === null || response === void 0 ? void 0 : response.choices[0].message;
|
|
39
28
|
if (finalMessage) {
|
|
40
|
-
let rootMessage =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
role: finalMessage.role,
|
|
47
|
-
content: typeof output === 'string' ? output : JSON.stringify(output)
|
|
48
|
-
};
|
|
29
|
+
let rootMessage = {
|
|
30
|
+
role: finalMessage.role,
|
|
31
|
+
content: typeof output === 'string' ? output : JSON.stringify(output),
|
|
32
|
+
reasoning: finalMessage.reasoning,
|
|
33
|
+
reasoning_details: finalMessage.reasoning_details,
|
|
34
|
+
};
|
|
49
35
|
chatHistoryMessages.push(rootMessage);
|
|
50
36
|
}
|
|
51
37
|
for (const msg of chatHistoryMessages) {
|
|
52
|
-
if (!
|
|
53
|
-
delete msg.reasoning_details;
|
|
38
|
+
if (!includeReasoning && msg.role === 'assistant') {
|
|
54
39
|
delete msg.reasoning;
|
|
40
|
+
delete msg.reasoning_details;
|
|
55
41
|
}
|
|
56
42
|
}
|
|
57
43
|
outputData.forEach((item) => {
|
|
@@ -72,7 +58,6 @@ function reorderOutputFields(outputData) {
|
|
|
72
58
|
output: item.json.output,
|
|
73
59
|
error: item.json.error,
|
|
74
60
|
request: item.json.request,
|
|
75
|
-
tool_calls: item.json.tool_calls,
|
|
76
61
|
response: item.json.response,
|
|
77
62
|
chat_history: item.json.chat_history,
|
|
78
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outputData.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/outputData.ts"],"names":[],"mappings":";;AAYA,
|
|
1
|
+
{"version":3,"file":"outputData.js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C,CAAC;IACJ,CAAC;IAGD,IAAI,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,CAAC,CAAC,CAAC;IACJ,CAAC;IAGD,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAEhC,OAAO,UAAU,CAAC;AACnB,CAAC;AAMD,SAAgB,mBAAmB,CAAC,UAAgC;IACnE,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,MAAM,SAAS,GAAG;YACjB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YACxB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;YACtB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YAE1B,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAC5B,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY;SACpC,CAAC;QAGF,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,WAAW,CAC7B,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CACrE,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IDataObject } from 'n8n-workflow';
|
|
2
|
+
export interface RetryState {
|
|
3
|
+
retriesRemaining: number;
|
|
4
|
+
attemptNumber: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function waitBeforeRetry(delayMs?: number): Promise<void>;
|
|
7
|
+
export declare function updateRetryState(state: RetryState): RetryState;
|
|
8
|
+
export declare function handleParseError(parseError: string, response: any, messages: IDataObject[], retryState: RetryState, structuredOutputToolsMode: boolean, structuredOutputTool: IDataObject | null | undefined, structuredOutputName: string | undefined, tools: any[]): Promise<boolean>;
|
|
9
|
+
export declare function handleValidationError(validationError: string, output: any, response: any, messages: IDataObject[], retryState: RetryState, structuredOutputToolsMode: boolean, structuredOutputTool: IDataObject | null | undefined, structuredOutputName?: string): Promise<boolean>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitBeforeRetry = waitBeforeRetry;
|
|
4
|
+
exports.updateRetryState = updateRetryState;
|
|
5
|
+
exports.handleParseError = handleParseError;
|
|
6
|
+
exports.handleValidationError = handleValidationError;
|
|
7
|
+
const validation_1 = require("../request/validation");
|
|
8
|
+
async function waitBeforeRetry(delayMs = 3000) {
|
|
9
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
10
|
+
}
|
|
11
|
+
function updateRetryState(state) {
|
|
12
|
+
return {
|
|
13
|
+
retriesRemaining: state.retriesRemaining - 1,
|
|
14
|
+
attemptNumber: state.attemptNumber + 1,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function isAssistantMessageEmpty(assistantMessage) {
|
|
18
|
+
const content = assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.content;
|
|
19
|
+
const hasContent = content !== null && content !== undefined && content !== '';
|
|
20
|
+
const hasToolCalls = (assistantMessage === null || assistantMessage === void 0 ? void 0 : assistantMessage.tool_calls) && assistantMessage.tool_calls.length > 0;
|
|
21
|
+
return !hasContent && !hasToolCalls;
|
|
22
|
+
}
|
|
23
|
+
async function handleParseError(parseError, response, messages, retryState, structuredOutputToolsMode, structuredOutputTool, structuredOutputName, tools) {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
25
|
+
if (retryState.retriesRemaining === 0) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const assistantMessage = (_b = (_a = response === null || response === void 0 ? void 0 : response.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message;
|
|
29
|
+
if (isAssistantMessageEmpty(assistantMessage)) {
|
|
30
|
+
await waitBeforeRetry();
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (structuredOutputToolsMode) {
|
|
34
|
+
messages.push({
|
|
35
|
+
role: 'assistant',
|
|
36
|
+
content: ((_e = (_d = (_c = response === null || response === void 0 ? void 0 : response.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.content) || '',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
messages.push(response.choices[0].message);
|
|
41
|
+
}
|
|
42
|
+
const schemaName = structuredOutputTool ? (_f = structuredOutputTool.function) === null || _f === void 0 ? void 0 : _f.name : structuredOutputName || 'final_response';
|
|
43
|
+
const toolNames = tools.map(tool => { var _a; return ((_a = tool.function) === null || _a === void 0 ? void 0 : _a.name) || 'unknown'; }).join(', ');
|
|
44
|
+
let errorMessage = `Your previous response (attempt ${retryState.attemptNumber})`;
|
|
45
|
+
if (structuredOutputToolsMode) {
|
|
46
|
+
errorMessage += ` did not correctly call a tool.\n\nYou MUST call one of the available tools: ${toolNames}`;
|
|
47
|
+
}
|
|
48
|
+
else if (tools.length > 0) {
|
|
49
|
+
errorMessage += ` had an invalid format.\n\nYou MUST either respond with valid JSON that strictly follows the \`${schemaName}\` schema, or call one of the available tools: ${toolNames}`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
errorMessage += ` had an invalid format.\n\nYou MUST respond with valid JSON that strictly follows the \`${schemaName}\` schema.`;
|
|
53
|
+
}
|
|
54
|
+
messages.push({
|
|
55
|
+
role: 'system',
|
|
56
|
+
content: errorMessage,
|
|
57
|
+
});
|
|
58
|
+
await waitBeforeRetry();
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
async function handleValidationError(validationError, output, response, messages, retryState, structuredOutputToolsMode, structuredOutputTool, structuredOutputName) {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
if (retryState.retriesRemaining === 0) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const assistantMessage = (_b = (_a = response === null || response === void 0 ? void 0 : response.choices) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message;
|
|
67
|
+
if (isAssistantMessageEmpty(assistantMessage)) {
|
|
68
|
+
await waitBeforeRetry();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (structuredOutputToolsMode) {
|
|
72
|
+
messages.push({
|
|
73
|
+
role: 'assistant',
|
|
74
|
+
content: JSON.stringify(output),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
messages.push(response.choices[0].message);
|
|
79
|
+
}
|
|
80
|
+
const schemaName = structuredOutputTool ? (_c = structuredOutputTool.function) === null || _c === void 0 ? void 0 : _c.name : structuredOutputName;
|
|
81
|
+
const errorMessage = (0, validation_1.formatValidationErrorMessage)(validationError, retryState.attemptNumber, structuredOutputToolsMode, schemaName);
|
|
82
|
+
messages.push({
|
|
83
|
+
role: 'system',
|
|
84
|
+
content: errorMessage,
|
|
85
|
+
});
|
|
86
|
+
await waitBeforeRetry();
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=retryHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryHandler.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/retryHandler.ts"],"names":[],"mappings":";;AAcA,0CAEC;AAKD,4CAKC;AAgBD,4CAwDC;AAMD,sDAoDC;AA3JD,sDAAqE;AAa9D,KAAK,UAAU,eAAe,CAAC,UAAkB,IAAI;IAC3D,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAKD,SAAgB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O,KAAK,CAAC;IACd,CAAC;IAGD,MAAM,gBAAgB,GAAG,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,0CAAG,CAAC,CAAC,0CAAE,OAAO,CAAC;IACzD,IAAI,uBAAuB,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAE/C,MAAM,eAAe,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACb,CAAC;IAGD,IAAI,yBAAyB,EAAE,CAAC;QAE/B,QAAQ,CAAC,IAAI,CAAC;YACb,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC/B,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QAEP,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAGD,MAAM,UAAU,GAAG,oBAAoB,CAAC,CAAC,CAAC,MAAC,oBAAoB,CAAC,QAAwB,0CAAE,IAAc,CAAC,CAAC,CAAC,oBAAoB,CAAC;IAChI,MAAM,YAAY,GAAG,IAAA,yCAA4B,EAChD,eAAe,EACf,UAAU,CAAC,aAAa,EACxB,yBAAyB,EACzB,UAAU,CACV,CAAC;IAEF,QAAQ,CAAC,IAAI,CAAC;QACb,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,YAAY;KACrB,CAAC,CAAC;IAGH,MAAM,eAAe,EAAE,CAAC;IAExB,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -36,16 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.router = router;
|
|
37
37
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
38
38
|
const messageOperation = __importStar(require("./messageOperation"));
|
|
39
|
-
const
|
|
40
|
-
function isNodeApiError(error) {
|
|
41
|
-
return error instanceof n8n_workflow_1.NodeApiError || error.name === 'NodeApiError';
|
|
42
|
-
}
|
|
43
|
-
function normalizeError(error) {
|
|
44
|
-
if (error instanceof Error) {
|
|
45
|
-
return error;
|
|
46
|
-
}
|
|
47
|
-
return new Error(String(error));
|
|
48
|
-
}
|
|
39
|
+
const errors_1 = require("./errors");
|
|
49
40
|
function initializeRouter(executeFunctions) {
|
|
50
41
|
return {
|
|
51
42
|
returnData: [],
|
|
@@ -57,8 +48,7 @@ async function executeItem(execute, executeFunctions, itemIndex) {
|
|
|
57
48
|
return await execute.call(executeFunctions, itemIndex);
|
|
58
49
|
}
|
|
59
50
|
function handleError(error, executeFunctions, itemIndex, continueOnFail, returnData) {
|
|
60
|
-
|
|
61
|
-
const normalizedError = normalizeError(error);
|
|
51
|
+
const normalizedError = (0, errors_1.normalizeError)(error);
|
|
62
52
|
if (continueOnFail) {
|
|
63
53
|
returnData.push({
|
|
64
54
|
json: { error: normalizedError.message },
|
|
@@ -66,18 +56,8 @@ function handleError(error, executeFunctions, itemIndex, continueOnFail, returnD
|
|
|
66
56
|
});
|
|
67
57
|
return returnData;
|
|
68
58
|
}
|
|
69
|
-
if (isNodeApiError(normalizedError)) {
|
|
70
|
-
const nodeApiError = normalizedError;
|
|
71
|
-
const errorCode = (_c = (_b = (_a = nodeApiError.cause) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.code;
|
|
72
|
-
if (errorCode) {
|
|
73
|
-
const customErrorMessage = (0, errorHandling_1.getCustomErrorMessage)(errorCode);
|
|
74
|
-
if (customErrorMessage) {
|
|
75
|
-
nodeApiError.message = customErrorMessage;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (nodeApiError.requestBody) {
|
|
79
|
-
nodeApiError.description += ` | Request Body: ${nodeApiError.requestBody}`;
|
|
80
|
-
}
|
|
59
|
+
if ((0, errors_1.isNodeApiError)(normalizedError)) {
|
|
60
|
+
const nodeApiError = (0, errors_1.customizeNodeApiError)(normalizedError);
|
|
81
61
|
nodeApiError.context = {
|
|
82
62
|
itemIndex,
|
|
83
63
|
description: nodeApiError.description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/execution/router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,wBASC;AA9HD,+CAIsB;AAEtB,qEAAuD;AACvD,qCAAiF;AAKjF,SAAS,gBAAgB,CAAC,gBAAmC;IAC5D,OAAO;QACN,UAAU,EAAE,EAA0B;QACtC,KAAK,EAAE,gBAAgB,CAAC,YAAY,EAAE;QACtC,OAAO,EAAE,gBAAgB,CAAC,OAAO;KACjC,CAAC;AACH,CAAC;AAKD,KAAK,UAAU,WAAW,CACzB,OAAwC,EACxC,gBAAmC,EACnC,SAAiB;IAEjB,OAAO,MAAM,OAAO,CAAC,IAAI,CACxB,gBAAgB,EAChB,SAAS,CACT,CAAC;AACH,CAAC;AAKD,SAAS,WAAW,CACnB,KAAc,EACd,gBAAmC,EACnC,SAAiB,EACjB,cAAuB,EACvB,UAAgC;IAGhC,MAAM,eAAe,GAAG,IAAA,uBAAc,EAAC,KAAK,CAAC,CAAC;IAE9C,IAAI,cAAc,EAAE,CAAC;QACpB,UAAU,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,EAAE;YACxC,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;SAC/B,CAAC,CAAC;QACH,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,IAAI,IAAA,uBAAc,EAAC,eAAe,CAAC,EAAE,CAAC;QAErC,MAAM,YAAY,GAAG,IAAA,8BAAqB,EAAC,eAAe,CAAC,CAAC;QAE5D,YAAY,CAAC,OAAO,GAAG;YACtB,S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
1
|
import type { IDataObject } from 'n8n-workflow';
|
|
2
|
-
export declare function prepareRequestBody(model: string, messages: IDataObject[], tools: any[], tool_choice: string | undefined, response_format: IDataObject | undefined, options: IDataObject, customParameters: string | IDataObject): IDataObject;
|
|
2
|
+
export declare function prepareRequestBody(model: string, messages: IDataObject[], tools: any[], tool_choice: string | IDataObject | undefined, response_format: IDataObject | undefined, options: IDataObject, customParameters: string | IDataObject): IDataObject;
|
|
@@ -25,21 +25,15 @@ function prepareRequestBody(model, messages, tools, tool_choice, response_format
|
|
|
25
25
|
}
|
|
26
26
|
const cleanOptions = (0, omit_1.default)(options, [
|
|
27
27
|
'customParameters',
|
|
28
|
-
'fallbackModelId',
|
|
29
28
|
'maxToolsIterations',
|
|
30
|
-
'
|
|
29
|
+
'tenacityMaxRetries'
|
|
31
30
|
]);
|
|
32
|
-
const reasoningEffort = options.reasoning_effort;
|
|
33
|
-
const reasoning = reasoningEffort && reasoningEffort !== ''
|
|
34
|
-
? { reasoning: { effort: reasoningEffort } }
|
|
35
|
-
: undefined;
|
|
36
31
|
const body = {
|
|
37
32
|
model,
|
|
38
33
|
messages,
|
|
39
34
|
...(tools.length > 0 ? { tools } : {}),
|
|
40
35
|
tool_choice,
|
|
41
36
|
response_format,
|
|
42
|
-
...reasoning,
|
|
43
37
|
...cleanOptions,
|
|
44
38
|
...customParamsObj,
|
|
45
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/request/body.ts"],"names":[],"mappings":";;;;;AAOA,
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../../../../nodes/shared/core/request/body.ts"],"names":[],"mappings":";;;;;AAOA,gDAgDC;AAtDD,uDAAgC;AAChC,6CAAqD;AAKrD,SAAgB,kBAAkB,CACjC,KAAa,EACb,QAAuB,EACvB,KAAY,EACZ,WAA6C,EAC7C,eAAwC,EACxC,OAAoB,EACpB,gBAAsC;IAGtC,IA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
|
|
4
|
+
error?: string;
|
|
5
|
+
errors?: Array<{
|
|
6
|
+
path: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare function validateStructuredOutput(jsonSchema: IDataObject | undefined, output: any): ValidationResult;
|
|
11
|
+
export declare function formatValidationErrorMessage(validationError: string, attemptNumber: number, structuredOutputToolsMode?: boolean, schemaName?: string): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateStructuredOutput = validateStructuredOutput;
|
|
4
|
+
exports.formatValidationErrorMessage = formatValidationErrorMessage;
|
|
5
|
+
const schemaGenerator_1 = require("../tools/schemaGenerator");
|
|
6
|
+
function validateStructuredOutput(jsonSchema, output) {
|
|
7
|
+
if (!jsonSchema) {
|
|
8
|
+
return { isValid: true };
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const zodSchema = (0, schemaGenerator_1.convertJsonSchemaToZod)(jsonSchema);
|
|
12
|
+
const result = zodSchema.safeParse(output);
|
|
13
|
+
if (result.success) {
|
|
14
|
+
return { isValid: true };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const errors = result.error.errors.map((err) => ({
|
|
18
|
+
path: err.path.join('.'),
|
|
19
|
+
message: err.message,
|
|
20
|
+
}));
|
|
21
|
+
const errorMessage = errors
|
|
22
|
+
.map((err) => ` - ${err.path ? `${err.path}: ` : ''}${err.message}`)
|
|
23
|
+
.join('\n');
|
|
24
|
+
return {
|
|
25
|
+
isValid: false,
|
|
26
|
+
error: `Validation failed:\n${errorMessage}`,
|
|
27
|
+
errors,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return {
|
|
33
|
+
isValid: false,
|
|
34
|
+
error: `Schema validation error: ${error instanceof Error ? error.message : String(error)}`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function formatValidationErrorMessage(validationError, attemptNumber, structuredOutputToolsMode = false, schemaName) {
|
|
39
|
+
const baseMessage = `Your previous response (attempt ${attemptNumber}) did not conform to the required JSON schema. Please correct the following validation errors and try again:\n\n${validationError}\n\n`;
|
|
40
|
+
if (structuredOutputToolsMode && schemaName) {
|
|
41
|
+
return baseMessage + `You MUST call the \`${schemaName}\` tool with corrected arguments that strictly follow the required schema.`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return baseMessage + 'Ensure your response strictly follows the schema requirements.';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=validation.js.map
|