n8n-nodes-simple 2.0.0 → 2.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/dist/credentials/SimpleOpenAiApi.credentials.js +1 -1
- package/dist/credentials/SimpleOpenAiApi.credentials.js.map +1 -1
- package/dist/nodes/CoreAgent/CoreAgent.node.js.map +1 -1
- package/dist/nodes/CoreAgent/description.js +14 -2
- package/dist/nodes/CoreAgent/description.js.map +1 -1
- package/dist/nodes/Subagent/description.js +15 -2
- package/dist/nodes/Subagent/description.js.map +1 -1
- package/dist/nodes/shared/actions/executor.js +1 -1
- package/dist/nodes/shared/actions/executor.js.map +1 -1
- package/dist/nodes/shared/actions/memory.d.ts +1 -1
- package/dist/nodes/shared/actions/memory.js +71 -19
- package/dist/nodes/shared/actions/memory.js.map +1 -1
- package/dist/nodes/shared/actions/message.operation.js +1 -1
- package/dist/nodes/shared/actions/message.operation.js.map +1 -1
- package/dist/nodes/shared/actions/messageProcessor.d.ts +1 -1
- package/dist/nodes/shared/actions/messageProcessor.js +9 -7
- package/dist/nodes/shared/actions/messageProcessor.js.map +1 -1
- package/dist/nodes/shared/actions/outputProcessor.js +29 -21
- package/dist/nodes/shared/actions/outputProcessor.js.map +1 -1
- package/dist/nodes/shared/actions/parameters.d.ts +2 -0
- package/dist/nodes/shared/actions/parameters.js +8 -1
- package/dist/nodes/shared/actions/parameters.js.map +1 -1
- package/dist/nodes/shared/actions/requestBuilder.js +2 -2
- package/dist/nodes/shared/actions/requestBuilder.js.map +1 -1
- package/dist/nodes/shared/actions/responseConfig.js +2 -2
- package/dist/nodes/shared/actions/responseConfig.js.map +1 -1
- package/dist/nodes/shared/actions/router.js +2 -2
- package/dist/nodes/shared/actions/router.js.map +1 -1
- package/dist/nodes/shared/actions/tool.js.map +1 -1
- package/dist/nodes/shared/actions/toolExecutor.js +78 -21
- package/dist/nodes/shared/actions/toolExecutor.js.map +1 -1
- package/dist/nodes/shared/actions/toolSetup.js +6 -5
- package/dist/nodes/shared/actions/toolSetup.js.map +1 -1
- package/dist/nodes/shared/api/openAiApiRequest.js.map +1 -1
- package/dist/nodes/shared/api/types.d.ts +2 -0
- package/dist/nodes/shared/api/utils.js.map +1 -1
- package/dist/nodes/shared/descriptionGenerator.js +4 -8
- package/dist/nodes/shared/descriptionGenerator.js.map +1 -1
- package/dist/nodes/shared/message/chatHistoryProcessor.d.ts +2 -0
- package/dist/nodes/shared/message/chatHistoryProcessor.js +63 -0
- package/dist/nodes/shared/message/chatHistoryProcessor.js.map +1 -0
- package/dist/nodes/shared/message/memoryOptimizer.d.ts +3 -0
- package/dist/nodes/shared/message/memoryOptimizer.js +30 -0
- package/dist/nodes/shared/message/memoryOptimizer.js.map +1 -0
- package/dist/nodes/shared/message/messageConverter.d.ts +4 -0
- package/dist/nodes/shared/message/messageConverter.js +76 -0
- package/dist/nodes/shared/message/messageConverter.js.map +1 -0
- package/dist/nodes/shared/message/processor.d.ts +3 -7
- package/dist/nodes/shared/message/processor.js +8 -83
- package/dist/nodes/shared/message/processor.js.map +1 -1
- package/dist/nodes/shared/message/toolMessageExtractor.d.ts +6 -0
- package/dist/nodes/shared/message/toolMessageExtractor.js +28 -0
- package/dist/nodes/shared/message/toolMessageExtractor.js.map +1 -0
- package/dist/nodes/shared/message/types.d.ts +2 -0
- package/dist/nodes/shared/message/types.js +5 -5
- package/dist/nodes/shared/message/types.js.map +1 -1
- package/dist/nodes/shared/properties.js +75 -41
- package/dist/nodes/shared/properties.js.map +1 -1
- package/dist/nodes/shared/tool/subagentTool.d.ts +1 -1
- package/dist/nodes/shared/tool/subagentTool.js +4 -4
- package/dist/nodes/shared/tool/subagentTool.js.map +1 -1
- package/dist/nodes/shared/tool/visualEditor.d.ts +1 -1
- package/dist/nodes/shared/tool/visualEditor.js +20 -16
- package/dist/nodes/shared/tool/visualEditor.js.map +1 -1
- package/dist/nodes/shared/toolManager/getConnectedTools.js.map +1 -1
- package/dist/nodes/shared/toolManager/n8nTool.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,8 @@ exports.processToolCalls = processToolCalls;
|
|
|
4
4
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
5
|
const openAiApiRequest_1 = require("../api/openAiApiRequest");
|
|
6
6
|
async function processToolCalls(executeFunctions, body, messages, invokableTools, structuredOutputTool, maxToolsIterations, abortSignal) {
|
|
7
|
-
var _a, _b, _c;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f;
|
|
8
|
+
const processedToolCallIds = new Set();
|
|
8
9
|
let response = (await openAiApiRequest_1.openAiApiRequest.call(executeFunctions, 'POST', `/chat/completions`, {
|
|
9
10
|
body,
|
|
10
11
|
}));
|
|
@@ -12,42 +13,95 @@ async function processToolCalls(executeFunctions, body, messages, invokableTools
|
|
|
12
13
|
throw new Error(String(response.error));
|
|
13
14
|
}
|
|
14
15
|
if (!response) {
|
|
15
|
-
throw new Error(
|
|
16
|
+
throw new Error('No response received from OpenAI API');
|
|
16
17
|
}
|
|
17
18
|
let toolCalls = (_b = (_a = response === null || response === void 0 ? void 0 : response.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.tool_calls;
|
|
18
19
|
let currentIteration = 1;
|
|
19
20
|
var output = null;
|
|
20
21
|
while (toolCalls === null || toolCalls === void 0 ? void 0 : toolCalls.length) {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const shouldMakeFinalCall = maxToolsIterations >= 0 && currentIteration > maxToolsIterations;
|
|
23
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
if (shouldMakeFinalCall) {
|
|
27
|
+
let finalBody;
|
|
28
|
+
if (structuredOutputTool && !output) {
|
|
29
|
+
finalBody = {
|
|
30
|
+
...body,
|
|
31
|
+
messages: messages,
|
|
32
|
+
tools: [structuredOutputTool],
|
|
33
|
+
tool_choice: 'required',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
finalBody = {
|
|
38
|
+
...body,
|
|
39
|
+
messages: messages,
|
|
40
|
+
tools: [],
|
|
41
|
+
tool_choice: undefined,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
response = (await openAiApiRequest_1.openAiApiRequest.call(executeFunctions, 'POST', `/chat/completions`, {
|
|
45
|
+
body: finalBody,
|
|
46
|
+
}));
|
|
47
|
+
if (structuredOutputTool && !output && ((_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.tool_calls)) {
|
|
48
|
+
const finalToolCalls = response.choices[0].message.tool_calls;
|
|
49
|
+
for (const toolCall of finalToolCalls) {
|
|
50
|
+
if (structuredOutputTool.function.name ===
|
|
51
|
+
toolCall.function.name) {
|
|
52
|
+
output = (0, n8n_workflow_1.jsonParse)(toolCall.function.arguments);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
23
57
|
break;
|
|
24
58
|
}
|
|
25
59
|
for (const toolCall of toolCalls) {
|
|
26
60
|
const calledFunctionName = toolCall.function.name;
|
|
27
61
|
const calledFunctionArgs = toolCall.function.arguments;
|
|
62
|
+
const toolCallId = toolCall.id;
|
|
63
|
+
if (processedToolCallIds.has(toolCallId)) {
|
|
64
|
+
console.log(`Skipping duplicate tool call ID: ${toolCallId}`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
processedToolCallIds.add(toolCallId);
|
|
28
68
|
let content = null;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
69
|
+
let toolFound = false;
|
|
70
|
+
try {
|
|
71
|
+
for (const invokableTool of invokableTools !== null && invokableTools !== void 0 ? invokableTools : []) {
|
|
72
|
+
if (structuredOutputTool &&
|
|
73
|
+
structuredOutputTool.function.name === calledFunctionName) {
|
|
74
|
+
output = (0, n8n_workflow_1.jsonParse)(calledFunctionArgs);
|
|
75
|
+
toolFound = true;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (invokableTool.name === calledFunctionName) {
|
|
79
|
+
const parsedArgs = (0, n8n_workflow_1.jsonParse)(calledFunctionArgs);
|
|
80
|
+
content = await invokableTool.invoke(parsedArgs);
|
|
81
|
+
content =
|
|
82
|
+
Array.isArray(content) && typeof ((_f = content[0]) === null || _f === void 0 ? void 0 : _f.text) === 'string'
|
|
83
|
+
? content[0].text
|
|
84
|
+
: content;
|
|
85
|
+
toolFound = true;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
34
88
|
}
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
content = Array.isArray(content) && typeof ((_c = content[0]) === null || _c === void 0 ? void 0 : _c.text) === 'string'
|
|
39
|
-
? content[0].text
|
|
40
|
-
: content;
|
|
89
|
+
if (!toolFound) {
|
|
90
|
+
content = `Error: Tool '${calledFunctionName}' not found in available tools`;
|
|
91
|
+
console.error(`Tool not found: ${calledFunctionName}`);
|
|
41
92
|
}
|
|
42
93
|
}
|
|
43
|
-
|
|
94
|
+
catch (error) {
|
|
95
|
+
content = `Error executing tool '${calledFunctionName}': ${error instanceof Error ? error.message : String(error)}`;
|
|
96
|
+
}
|
|
44
97
|
if (output) {
|
|
45
98
|
break;
|
|
46
99
|
}
|
|
47
|
-
|
|
48
|
-
|
|
100
|
+
if (toolCalls.indexOf(toolCall) === 0) {
|
|
101
|
+
messages.push(response.choices[0].message);
|
|
102
|
+
}
|
|
49
103
|
messages.push({
|
|
50
|
-
tool_call_id:
|
|
104
|
+
tool_call_id: toolCallId,
|
|
51
105
|
role: 'tool',
|
|
52
106
|
content: typeof content === 'string' ? content : JSON.stringify(content),
|
|
53
107
|
});
|
|
@@ -55,9 +109,12 @@ async function processToolCalls(executeFunctions, body, messages, invokableTools
|
|
|
55
109
|
if (output) {
|
|
56
110
|
break;
|
|
57
111
|
}
|
|
58
|
-
|
|
112
|
+
const nextIterationBody = {
|
|
113
|
+
...body,
|
|
114
|
+
messages: messages,
|
|
115
|
+
};
|
|
59
116
|
response = (await openAiApiRequest_1.openAiApiRequest.call(executeFunctions, 'POST', `/chat/completions`, {
|
|
60
|
-
body,
|
|
117
|
+
body: nextIterationBody,
|
|
61
118
|
}));
|
|
62
119
|
toolCalls = response.choices[0].message.tool_calls;
|
|
63
120
|
currentIteration += 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolExecutor.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/toolExecutor.ts"],"names":[],"mappings":";;AAQA,
|
|
1
|
+
{"version":3,"file":"toolExecutor.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/toolExecutor.ts"],"names":[],"mappings":";;AAQA,4CAkLC;AAzLD,+CAAyC;AACzC,8DAA2D;AAMpD,KAAK,UAAU,gBAAgB,CACrC,gBAAmC,EACnC,IAAiB,EACjB,QAAuB,EACvB,cAAqB,EACrB,oBAA6C,EAC7C,kBAA0B,EAC1B,WAAoC;;IAMpC,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/C,IAAI,QAAQ,GAAG,CAAC,MAAM,mCAAgB,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE;QAC1F,IAAI;KACJ,CAAC,CAAmB,CAAC;IAEtB,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IAGD,IAAI,SAAS,GAAG,MAAA,MAAA,Q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MAAM,EAAE,CAAC;YACZ,MAAM;QACP,CAAC;QAGD,MAAM,iBAAiB,GAAG;YACzB,GAAG,IAAI;YACP,QAAQ,EAAE,QAAQ;SAClB,CAAC;QAGF,QAAQ,GAAG,CAAC,MAAM,mCAAgB,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE;YACtF,IAAI,EAAE,iBAAiB;SACvB,CAAC,CAAmB,CAAC;QAGtB,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;QACnD,gBAAgB,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -38,13 +38,14 @@ async function setupTools(executeFunctions, structuredOutputToolsMode, responseF
|
|
|
38
38
|
type: 'function',
|
|
39
39
|
function: {
|
|
40
40
|
name: jsonSchema.name,
|
|
41
|
-
description: jsonSchema.description ||
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
description: jsonSchema.description ||
|
|
42
|
+
'Call this function last, when you are ready to generate the final response to the user',
|
|
43
|
+
parameters: jsonSchema.schema,
|
|
44
|
+
},
|
|
44
45
|
};
|
|
45
46
|
tools.push(structuredOutputTool);
|
|
46
47
|
invokableTools.push({ name: structuredOutputTool.function.name });
|
|
47
|
-
tool_choice =
|
|
48
|
+
tool_choice = 'required';
|
|
48
49
|
updatedResponseFormat = undefined;
|
|
49
50
|
}
|
|
50
51
|
return {
|
|
@@ -52,7 +53,7 @@ async function setupTools(executeFunctions, structuredOutputToolsMode, responseF
|
|
|
52
53
|
invokableTools,
|
|
53
54
|
tool_choice,
|
|
54
55
|
structuredOutputTool,
|
|
55
|
-
updatedResponseFormat
|
|
56
|
+
updatedResponseFormat,
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
//# sourceMappingURL=toolSetup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolSetup.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/toolSetup.ts"],"names":[],"mappings":";;AAQA,
|
|
1
|
+
{"version":3,"file":"toolSetup.js","sourceRoot":"","sources":["../../../../nodes/shared/actions/toolSetup.ts"],"names":[],"mappings":";;AAQA,gCAsEC;AA5ED,wEAAqE;AACrE,wCAAkD;AAK3C,KAAK,UAAU,UAAU,CAC/B,gBAAmC,EACnC,yBAAkC,EAClC,cAAuC;IAQvC,IAAI,KAAK,GAAU,EAAE,CAAC;IACtB,IAAI,aAAa,GAAW,EAAE,CAAC;IAC/B,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAChC,IAAI,WAAW,GAAG,SAAS,CAAC;IAC5B,IAAI,oBAAoB,GAAG,SAAS,CAAC;IACrC,IAAI,qBAAqB,GAAG,cAAc,CAAC;IAE3C,IAAI,CAAC;QACJ,aAAa,GAAG,MAAM,IAAA,qCAAiB,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACtF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QAEvD,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClD,aAAa,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,cAAc,GAAU,EAAE,CAAC;IAE/B,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;QAE1B,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;YAElC,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBAClC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC;IACF,CAAC;IAED,KAAK,GAAG,cAAc,CAAC,GAAG,CAAC,0BAAkB,CAAC,CAAC;IAE/C,IAAI,yBAAyB,IAAI,cAAc,IAAI,cAAc,CAAC,WAAW,EAAE,CAAC;QAC/E,MAAM,UAAU,GAAG,cAAc,CAAC,WAA0B,CAAC;QAC7D,oBAAoB,GAAG;YACtB,IAAI,EAAE,UAAmB;YACzB,QAAQ,EAAE;gBACT,IAAI,EAAE,UAAU,CAAC,IAAc;gBAC/B,WAAW,EACT,UAAU,CAAC,WAAsB;oBAClC,wFAAwF;gBACzF,UAAU,EAAE,UAAU,CAAC,MAAqB;aAC5C;SACD,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACjC,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAG,oBAAoB,CAAC,QAAwB,CAAC,IAAc,EAAE,CAAC,CAAC;QAC7F,WAAW,GAAG,UAAU,CAAC;QACzB,qBAAqB,GAAG,SAAS,CAAC;IACnC,CAAC;IAED,OAAO;QACN,KAAK;QACL,cAAc;QACd,WAAW;QACX,oBAAoB;QACpB,qBAAqB;KACrB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openAiApiRequest.js","sourceRoot":"","sources":["../../../../nodes/shared/api/openAiApiRequest.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"openAiApiRequest.js","sourceRoot":"","sources":["../../../../nodes/shared/api/openAiApiRequest.ts"],"names":[],"mappings":";;AAeA,4CA8BC;AA9BM,KAAK,UAAU,gBAAgB,CAErC,MAA2B,EAC3B,QAAgB,EAChB,UAA8B;IAE9B,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC;IAG5D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC;IAG3E,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC;IAE/E,MAAM,OAAO,GAAG;QACf,OAAO;QACP,MAAM;QACN,IAAI;QACJ,EAAE;QACF,GAAG,EAAE,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,GAAG,gBAAgB,GAAG,iBAAiB,EAAE;QACrD,IAAI,EAAE,IAAI;KACV,CAAC;IAEF,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAC5F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../nodes/shared/api/utils.ts"],"names":[],"mappings":";;AAcA,wDAQC;AAED,0CAsBC;AAED,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../nodes/shared/api/utils.ts"],"names":[],"mappings":";;AAcA,wDAQC;AAED,0CAsBC;AAED,gDAkBC;AAjED,2DAAqD;AAarD,SAAgB,sBAAsB,CACrC,IAAoB;IAEpB,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,U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
7
|
displayName: 'Simple Agent',
|
|
8
8
|
name: agentType,
|
|
9
9
|
group: [],
|
|
10
|
-
version:
|
|
10
|
+
version: 1,
|
|
11
11
|
description: 'Agent capable of using tools, subagents, and structured output.',
|
|
12
12
|
defaults: { name: 'Simple Agent' },
|
|
13
13
|
subtitle: '={{ ($parameter.name ? `${$parameter.name} | ` : ``) + ($parameter.modelId.split("/")[1] || $parameter.modelId) }}',
|
|
@@ -20,20 +20,16 @@ function generateDescription(agentType, customizations) {
|
|
|
20
20
|
: [
|
|
21
21
|
{ type: 'main' },
|
|
22
22
|
{ type: 'ai_tool', displayName: 'Tools' },
|
|
23
|
-
{ type: 'ai_memory', displayName: 'Memory', maxConnections: 1 }
|
|
23
|
+
{ type: 'ai_memory', displayName: 'Memory', maxConnections: 1 },
|
|
24
24
|
],
|
|
25
|
-
outputs: agentType === 'subAgent'
|
|
26
|
-
? [{ type: 'ai_tool', displayName: 'Tool' }]
|
|
27
|
-
: [{ type: 'main' }],
|
|
25
|
+
outputs: agentType === 'subAgent' ? [{ type: 'ai_tool', displayName: 'Tool' }] : [{ type: 'main' }],
|
|
28
26
|
credentials: [
|
|
29
27
|
{
|
|
30
28
|
name: 'simpleOpenAiApi',
|
|
31
29
|
required: true,
|
|
32
30
|
},
|
|
33
31
|
],
|
|
34
|
-
properties: [
|
|
35
|
-
...(0, properties_1.getProperties)(agentType),
|
|
36
|
-
],
|
|
32
|
+
properties: [...(0, properties_1.getProperties)(agentType)],
|
|
37
33
|
...customizations,
|
|
38
34
|
};
|
|
39
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descriptionGenerator.js","sourceRoot":"","sources":["../../../nodes/shared/descriptionGenerator.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"descriptionGenerator.js","sourceRoot":"","sources":["../../../nodes/shared/descriptionGenerator.ts"],"names":[],"mappings":";;AAIA,kDAqCC;AAvCD,6CAA6C;AAE7C,SAAgB,mBAAmB,CAClC,SAAiB,EACjB,cAA6C;IAE7C,OAAO;QACN,WAAW,EAAE,cAAc;QAC3B,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,iEAAiE;QAC9E,QAAQ,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE;QAClC,QAAQ,EACP,oHAAoH;QACrH,IAAI,EAAE;YACL,KAAK,EAAE,kCAAkC;YACzC,IAAI,EAAE,kCAAkC;SACxC;QAED,MAAM,EACL,SAAS,KAAK,UAAU;YACvB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;YAC7C,CAAC,CAAC;gBACA,EAAE,IAAI,EAAE,MAAM,EAAE;gBAChB,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE;gBACzC,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,EAAE;aAC/D;QACJ,OAAO,EACN,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3F,WAAW,EAAE;YACZ;gBACC,IAAI,EAAE,iBAAiB;gBACvB,QAAQ,EAAE,IAAI;aACd;SACD;QACD,UAAU,EAAE,CAAC,GAAG,IAAA,0BAAa,EAAC,SAAS,CAAC,CAAC;QACzC,GAAG,cAAc;KACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unpackChatHistoryAndMemory = unpackChatHistoryAndMemory;
|
|
4
|
+
const memoryOptimizer_1 = require("./memoryOptimizer");
|
|
5
|
+
const messageConverter_1 = require("./messageConverter");
|
|
6
|
+
async function unpackChatHistoryAndMemory(rawMessagesToSend, memory, loadToolCallsFromChatMemory = true) {
|
|
7
|
+
const processedMessages = [];
|
|
8
|
+
for (const rawMessage of rawMessagesToSend) {
|
|
9
|
+
if (rawMessage.role !== 'chatHistoryRole' && rawMessage.role !== 'chatMemoryRole') {
|
|
10
|
+
processedMessages.push(rawMessage);
|
|
11
|
+
}
|
|
12
|
+
else if (rawMessage.role === 'chatHistoryRole') {
|
|
13
|
+
try {
|
|
14
|
+
let chatHistory;
|
|
15
|
+
if (typeof rawMessage.chatHistoryJson === 'string') {
|
|
16
|
+
chatHistory = JSON.parse(rawMessage.chatHistoryJson || '[]');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
chatHistory = rawMessage.chatHistoryJson;
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(chatHistory)) {
|
|
22
|
+
processedMessages.push(...chatHistory);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
processedMessages.push({
|
|
26
|
+
role: 'user',
|
|
27
|
+
content: JSON.stringify(rawMessage.chatHistoryJson),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
processedMessages.push({
|
|
33
|
+
role: 'user',
|
|
34
|
+
content: JSON.stringify(rawMessage.chatHistoryJson),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (rawMessage.role === 'chatMemoryRole' && memory && memory.chatHistory) {
|
|
39
|
+
try {
|
|
40
|
+
let k = memory.k;
|
|
41
|
+
if (k === 0 || !memory.k) {
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (k > 0 && k < 1) {
|
|
45
|
+
k = 1;
|
|
46
|
+
}
|
|
47
|
+
const rawMemoryMessages = await (0, memoryOptimizer_1.getLastKMessages)(memory, k);
|
|
48
|
+
if (rawMemoryMessages.length === 0) {
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const memoryMessages = (0, messageConverter_1.convertMessages)(rawMemoryMessages, loadToolCallsFromChatMemory);
|
|
52
|
+
processedMessages.push(...memoryMessages);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error('Error retrieving messages from memory:', error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return (0, messageConverter_1.expandToolCallsInMessages)(processedMessages, loadToolCallsFromChatMemory);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=chatHistoryProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatHistoryProcessor.js","sourceRoot":"","sources":["../../../../nodes/shared/message/chatHistoryProcessor.ts"],"names":[],"mappings":";;AAYA,gEA2EC;AArFD,uDAAqD;AACrD,yDAAgF;AASzE,KAAK,UAAU,0BAA0B,CAC/C,iBAA+B,EAC/B,MAAY,EACZ,8BAAuC,IAAI;IAE3C,MAAM,iBAAiB,GAAc,EAAE,CAAC;IAExC,KAAK,MAAM,UAAU,IAAI,iBAAiB,EAAE,CAAC;QAC5C,IAAI,UAAU,CAAC,IAAI,KAAK,iBAAiB,IAAI,UAAU,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAEnF,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;aAAM,IAAI,UAAU,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;YAClD,IAAI,CAAC;gBAEJ,IAAI,WAAW,CAAC;gBAChB,IAAI,OAAO,UAAU,CAAC,eAAe,KAAK,QAAQ,EAAE,CAAC;oBACpD,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC;gBAC9D,CAAC;qBAAM,CAAC;oBACP,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;gBAC1C,CAAC;gBAED,IAAI,KAAK,CAAC,OAAO,C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gBAChB,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;IACF,CAAC;IAGD,OAAO,IAAA,4CAAyB,EAAC,iBAAiB,EAAE,2BAA2B,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLastKMessages = getLastKMessages;
|
|
4
|
+
async function getLastKMessages(memory, k) {
|
|
5
|
+
if (!(memory === null || memory === void 0 ? void 0 : memory.chatHistory)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
if (k === 0) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
if (k === -1) {
|
|
12
|
+
return await memory.chatHistory.getMessages();
|
|
13
|
+
}
|
|
14
|
+
if (k > 0) {
|
|
15
|
+
const chatHistory = memory.chatHistory;
|
|
16
|
+
if (typeof chatHistory.getMessagesSlice === 'function') {
|
|
17
|
+
return await chatHistory.getMessagesSlice(-k);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof chatHistory.getLastMessages === 'function') {
|
|
20
|
+
return await chatHistory.getLastMessages(k);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const allMessages = await memory.chatHistory.getMessages();
|
|
24
|
+
const validK = Math.min(Math.max(k, 1), allMessages.length);
|
|
25
|
+
return allMessages.slice(-validK);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=memoryOptimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoryOptimizer.js","sourceRoot":"","sources":["../../../../nodes/shared/message/memoryOptimizer.ts"],"names":[],"mappings":";;AAOA,4CAwCC;AAxCM,KAAK,UAAU,gBAAgB,CAAC,MAAsB,EAAE,CAAS;IACvE,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAA,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACX,CAAC;IAGD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACX,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAEd,OAAO,MAAM,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;IAC/C,CAAC;IAGD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAGX,MAAM,WAAW,GAAG,MAAM,CAAC,WAAkB,CAAC;QAG9C,IAAI,OAAO,WAAW,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;YAExD,OAAO,MAAM,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,OAAO,WAAW,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;YAE9D,OAAO,MAAM,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YAGP,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;YAG3D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAC5D,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Message } from './types';
|
|
2
|
+
import { BaseMessage } from '@langchain/core/dist/messages/base';
|
|
3
|
+
export declare function convertMessages(messages: BaseMessage[], loadToolCalls?: boolean): Message[];
|
|
4
|
+
export declare function expandToolCallsInMessages(messages: Message[], loadToolCalls?: boolean): Message[];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertMessages = convertMessages;
|
|
4
|
+
exports.expandToolCallsInMessages = expandToolCallsInMessages;
|
|
5
|
+
function convertMessages(messages, loadToolCalls = true) {
|
|
6
|
+
const result = [];
|
|
7
|
+
for (const message of messages) {
|
|
8
|
+
const role = message.constructor.name === 'AIMessage' ? 'assistant' : 'user';
|
|
9
|
+
const content = typeof message.content === 'string' ? message.content : JSON.stringify(message.content);
|
|
10
|
+
if (role === 'assistant' &&
|
|
11
|
+
message.tool_calls &&
|
|
12
|
+
Array.isArray(message.tool_calls) &&
|
|
13
|
+
loadToolCalls) {
|
|
14
|
+
const toolCalls = message.tool_calls;
|
|
15
|
+
if (toolCalls.length > 0 && toolCalls[0].role) {
|
|
16
|
+
result.push(...toolCalls);
|
|
17
|
+
result.push({
|
|
18
|
+
role: 'assistant',
|
|
19
|
+
content: content,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
result.push({
|
|
24
|
+
role: role,
|
|
25
|
+
content: content,
|
|
26
|
+
tool_calls: toolCalls,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (role === 'assistant' &&
|
|
31
|
+
message.tool_calls &&
|
|
32
|
+
Array.isArray(message.tool_calls) &&
|
|
33
|
+
!loadToolCalls) {
|
|
34
|
+
result.push({
|
|
35
|
+
role: role,
|
|
36
|
+
content: content,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
result.push({
|
|
41
|
+
role: role,
|
|
42
|
+
content: content,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function expandToolCallsInMessages(messages, loadToolCalls = true) {
|
|
49
|
+
var _a;
|
|
50
|
+
const result = [];
|
|
51
|
+
for (const message of messages) {
|
|
52
|
+
if (message.role !== 'assistant' || !((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
53
|
+
result.push(message);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!loadToolCalls) {
|
|
57
|
+
result.push({
|
|
58
|
+
role: 'assistant',
|
|
59
|
+
content: message.content,
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const firstToolCall = message.tool_calls[0];
|
|
64
|
+
if (!firstToolCall.role) {
|
|
65
|
+
result.push(message);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
result.push(...message.tool_calls);
|
|
69
|
+
result.push({
|
|
70
|
+
role: 'assistant',
|
|
71
|
+
content: message.content,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=messageConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageConverter.js","sourceRoot":"","sources":["../../../../nodes/shared/message/messageConverter.ts"],"names":[],"mappings":";;AAeA,0CAwDC;AASD,8DAyCC;AA1GD,SAAgB,eAAe,CAAC,QAAuB,EAAE,gBAAyB,IAAI;IACrF,MAAM,MAAM,GAAc,EAAE,CAAC;IAE7B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC;QAC7E,MAAM,OAAO,GACZ,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAGzF,IACC,IAAI,KAAK,WAAW;YACnB,OAAe,CAAC,UAAU;YAC3B,KAAK,CAAC,OAAO,CAAE,OAAe,CAAC,UAAU,CAAC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QACV,CAAC;QAGD,IAAI,CAAC,aAAa,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,OAAO,CAAC,OAAO;aACxB,CAAC,CAAC;YACH,SAAS;QACV,CAAC;QAGD,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAQ,CAAC;QACnD,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAEzB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,SAAS;QACV,CAAC;QAGD,MAAM,CAAC,IAAI,CAAC,GAAI,OAAO,CAAC,UAA+B,CAAC,CAAC;QAGzD,MAAM,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,OAAO,CAAC,OAAO;SACxB,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
tool: string;
|
|
5
|
-
input: string;
|
|
6
|
-
output: string;
|
|
7
|
-
}[];
|
|
1
|
+
export { convertMessages, expandToolCallsInMessages } from './messageConverter';
|
|
2
|
+
export { extractToolMessages } from './toolMessageExtractor';
|
|
3
|
+
export { unpackChatHistoryAndMemory } from './chatHistoryProcessor';
|
|
@@ -1,86 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unpackChatHistoryAndMemory =
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
async function unpackChatHistoryAndMemory(rawMessagesToSend, memory) {
|
|
15
|
-
const processedMessages = [];
|
|
16
|
-
for (const rawMessage of rawMessagesToSend) {
|
|
17
|
-
if (rawMessage.role !== "chatHistoryRole" && rawMessage.role !== "chatMemoryRole") {
|
|
18
|
-
processedMessages.push(rawMessage);
|
|
19
|
-
}
|
|
20
|
-
else if (rawMessage.role === "chatHistoryRole") {
|
|
21
|
-
try {
|
|
22
|
-
let chatHistory;
|
|
23
|
-
if (typeof rawMessage.chatHistoryJson === 'string') {
|
|
24
|
-
chatHistory = JSON.parse(rawMessage.chatHistoryJson || "[]");
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
chatHistory = rawMessage.chatHistoryJson;
|
|
28
|
-
}
|
|
29
|
-
if (Array.isArray(chatHistory)) {
|
|
30
|
-
processedMessages.push(...chatHistory);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
processedMessages.push({
|
|
34
|
-
role: "user",
|
|
35
|
-
content: JSON.stringify(rawMessage.chatHistoryJson),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
processedMessages.push({
|
|
41
|
-
role: "user",
|
|
42
|
-
content: JSON.stringify(rawMessage.chatHistoryJson),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else if (rawMessage.role === "chatMemoryRole" && memory && memory.chatHistory) {
|
|
47
|
-
try {
|
|
48
|
-
const rawMemoryMessages = await memory.chatHistory.getMessages();
|
|
49
|
-
const memoryMessages = convertMessages(rawMemoryMessages);
|
|
50
|
-
const k = memory.k || memoryMessages.length;
|
|
51
|
-
const lastKMemoryMessages = memoryMessages.slice(-k);
|
|
52
|
-
processedMessages.push(...lastKMemoryMessages);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
console.error('Error retrieving messages from memory:', error);
|
|
56
|
-
}
|
|
57
|
-
;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return processedMessages;
|
|
61
|
-
}
|
|
62
|
-
function extractToolMessages(messagesFromRequestBody) {
|
|
63
|
-
const toolMessagesFromRequestBody = messagesFromRequestBody.filter((msg) => msg.role === "tool");
|
|
64
|
-
const processedToolMessages = [];
|
|
65
|
-
for (const message of messagesFromRequestBody) {
|
|
66
|
-
if (message.role === "assistant" && message.tool_calls && message.tool_calls.length > 0) {
|
|
67
|
-
for (const toolCall of message.tool_calls) {
|
|
68
|
-
const toolName = toolCall.function.name;
|
|
69
|
-
let toolInput = JSON.parse(toolCall.function.arguments);
|
|
70
|
-
if (toolInput.input && Object.entries(toolInput).length === 1) {
|
|
71
|
-
toolInput = toolInput.input;
|
|
72
|
-
}
|
|
73
|
-
const toolMessage = toolMessagesFromRequestBody.find((toolMsg) => toolMsg.tool_call_id === toolCall.id);
|
|
74
|
-
if (toolMessage) {
|
|
75
|
-
processedToolMessages.push({
|
|
76
|
-
tool: toolName,
|
|
77
|
-
input: toolInput,
|
|
78
|
-
output: toolMessage.content
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return processedToolMessages;
|
|
85
|
-
}
|
|
3
|
+
exports.unpackChatHistoryAndMemory = exports.extractToolMessages = exports.expandToolCallsInMessages = exports.convertMessages = void 0;
|
|
4
|
+
var messageConverter_1 = require("./messageConverter");
|
|
5
|
+
Object.defineProperty(exports, "convertMessages", { enumerable: true, get: function () { return messageConverter_1.convertMessages; } });
|
|
6
|
+
Object.defineProperty(exports, "expandToolCallsInMessages", { enumerable: true, get: function () { return messageConverter_1.expandToolCallsInMessages; } });
|
|
7
|
+
var toolMessageExtractor_1 = require("./toolMessageExtractor");
|
|
8
|
+
Object.defineProperty(exports, "extractToolMessages", { enumerable: true, get: function () { return toolMessageExtractor_1.extractToolMessages; } });
|
|
9
|
+
var chatHistoryProcessor_1 = require("./chatHistoryProcessor");
|
|
10
|
+
Object.defineProperty(exports, "unpackChatHistoryAndMemory", { enumerable: true, get: function () { return chatHistoryProcessor_1.unpackChatHistoryAndMemory; } });
|
|
86
11
|
//# sourceMappingURL=processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../../../../nodes/shared/message/processor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../../../../nodes/shared/message/processor.ts"],"names":[],"mappings":";;;AAGA,uDAAgF;AAAvE,mHAAA,eAAe,OAAA;AAAE,6HAAA,yBAAyB,OAAA;AACnD,+DAA6D;AAApD,2HAAA,mBAAmB,OAAA;AAC5B,+DAAoE;AAA3D,kIAAA,0BAA0B,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractToolMessages = extractToolMessages;
|
|
4
|
+
function extractToolMessages(messagesFromRequestBody) {
|
|
5
|
+
const toolMessagesFromRequestBody = messagesFromRequestBody.filter((msg) => msg.role === 'tool');
|
|
6
|
+
const processedToolMessages = [];
|
|
7
|
+
for (const message of messagesFromRequestBody) {
|
|
8
|
+
if (message.role === 'assistant' && message.tool_calls && message.tool_calls.length > 0) {
|
|
9
|
+
for (const toolCall of message.tool_calls) {
|
|
10
|
+
const toolName = toolCall.function.name;
|
|
11
|
+
let toolInput = JSON.parse(toolCall.function.arguments);
|
|
12
|
+
if (toolInput.input && Object.entries(toolInput).length === 1) {
|
|
13
|
+
toolInput = toolInput.input;
|
|
14
|
+
}
|
|
15
|
+
const toolMessage = toolMessagesFromRequestBody.find((toolMsg) => toolMsg.tool_call_id === toolCall.id);
|
|
16
|
+
if (toolMessage) {
|
|
17
|
+
processedToolMessages.push({
|
|
18
|
+
tool: toolName,
|
|
19
|
+
input: toolInput,
|
|
20
|
+
output: toolMessage.content,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return processedToolMessages;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=toolMessageExtractor.js.map
|