@n8n/n8n-nodes-langchain 1.102.0 → 1.103.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.
Files changed (73) hide show
  1. package/dist/known/credentials.json +1 -0
  2. package/dist/known/nodes.json +4 -0
  3. package/dist/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.js +7 -2
  4. package/dist/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.js.map +1 -1
  5. package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js +2 -0
  6. package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js.map +1 -1
  7. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js +55 -5
  8. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js.map +1 -1
  9. package/dist/nodes/mcp/McpClientTool/loadOptions.js +11 -2
  10. package/dist/nodes/mcp/McpClientTool/loadOptions.js.map +1 -1
  11. package/dist/nodes/mcp/McpClientTool/types.js.map +1 -1
  12. package/dist/nodes/mcp/McpClientTool/utils.js +21 -11
  13. package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
  14. package/dist/nodes/tools/ToolThink/ToolThink.node.js +5 -2
  15. package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
  16. package/dist/nodes/vendors/Anthropic/Anthropic.node.js +42 -0
  17. package/dist/nodes/vendors/Anthropic/Anthropic.node.js.map +1 -0
  18. package/dist/nodes/vendors/Anthropic/actions/descriptions.js +52 -0
  19. package/dist/nodes/vendors/Anthropic/actions/descriptions.js.map +1 -0
  20. package/dist/nodes/vendors/Anthropic/actions/document/analyze.operation.js +125 -0
  21. package/dist/nodes/vendors/Anthropic/actions/document/analyze.operation.js.map +1 -0
  22. package/dist/nodes/vendors/Anthropic/actions/document/index.js +64 -0
  23. package/dist/nodes/vendors/Anthropic/actions/document/index.js.map +1 -0
  24. package/dist/nodes/vendors/Anthropic/actions/file/delete.operation.js +61 -0
  25. package/dist/nodes/vendors/Anthropic/actions/file/delete.operation.js.map +1 -0
  26. package/dist/nodes/vendors/Anthropic/actions/file/get.operation.js +63 -0
  27. package/dist/nodes/vendors/Anthropic/actions/file/get.operation.js.map +1 -0
  28. package/dist/nodes/vendors/Anthropic/actions/file/index.js +94 -0
  29. package/dist/nodes/vendors/Anthropic/actions/file/index.js.map +1 -0
  30. package/dist/nodes/vendors/Anthropic/actions/file/list.operation.js +108 -0
  31. package/dist/nodes/vendors/Anthropic/actions/file/list.operation.js.map +1 -0
  32. package/dist/nodes/vendors/Anthropic/actions/file/upload.operation.js +126 -0
  33. package/dist/nodes/vendors/Anthropic/actions/file/upload.operation.js.map +1 -0
  34. package/dist/nodes/vendors/Anthropic/actions/image/analyze.operation.js +125 -0
  35. package/dist/nodes/vendors/Anthropic/actions/image/analyze.operation.js.map +1 -0
  36. package/dist/nodes/vendors/Anthropic/actions/image/index.js +64 -0
  37. package/dist/nodes/vendors/Anthropic/actions/image/index.js.map +1 -0
  38. package/dist/nodes/vendors/Anthropic/actions/node.type.js +17 -0
  39. package/dist/nodes/vendors/Anthropic/actions/node.type.js.map +1 -0
  40. package/dist/nodes/vendors/Anthropic/actions/prompt/generate.operation.js +87 -0
  41. package/dist/nodes/vendors/Anthropic/actions/prompt/generate.operation.js.map +1 -0
  42. package/dist/nodes/vendors/Anthropic/actions/prompt/improve.operation.js +154 -0
  43. package/dist/nodes/vendors/Anthropic/actions/prompt/improve.operation.js.map +1 -0
  44. package/dist/nodes/vendors/Anthropic/actions/prompt/index.js +95 -0
  45. package/dist/nodes/vendors/Anthropic/actions/prompt/index.js.map +1 -0
  46. package/dist/nodes/vendors/Anthropic/actions/prompt/templatize.operation.js +146 -0
  47. package/dist/nodes/vendors/Anthropic/actions/prompt/templatize.operation.js.map +1 -0
  48. package/dist/nodes/vendors/Anthropic/actions/router.js +93 -0
  49. package/dist/nodes/vendors/Anthropic/actions/router.js.map +1 -0
  50. package/dist/nodes/vendors/Anthropic/actions/text/index.js +64 -0
  51. package/dist/nodes/vendors/Anthropic/actions/text/index.js.map +1 -0
  52. package/dist/nodes/vendors/Anthropic/actions/text/message.operation.js +540 -0
  53. package/dist/nodes/vendors/Anthropic/actions/text/message.operation.js.map +1 -0
  54. package/dist/nodes/vendors/Anthropic/actions/versionDescription.js +125 -0
  55. package/dist/nodes/vendors/Anthropic/actions/versionDescription.js.map +1 -0
  56. package/dist/nodes/vendors/Anthropic/anthropic.svg +1 -0
  57. package/dist/nodes/vendors/Anthropic/helpers/baseAnalyze.js +109 -0
  58. package/dist/nodes/vendors/Anthropic/helpers/baseAnalyze.js.map +1 -0
  59. package/dist/nodes/vendors/Anthropic/helpers/interfaces.js +17 -0
  60. package/dist/nodes/vendors/Anthropic/helpers/interfaces.js.map +1 -0
  61. package/dist/nodes/vendors/Anthropic/helpers/utils.js +84 -0
  62. package/dist/nodes/vendors/Anthropic/helpers/utils.js.map +1 -0
  63. package/dist/nodes/vendors/Anthropic/methods/index.js +39 -0
  64. package/dist/nodes/vendors/Anthropic/methods/index.js.map +1 -0
  65. package/dist/nodes/vendors/Anthropic/methods/listSearch.js +42 -0
  66. package/dist/nodes/vendors/Anthropic/methods/listSearch.js.map +1 -0
  67. package/dist/nodes/vendors/Anthropic/transport/index.js +57 -0
  68. package/dist/nodes/vendors/Anthropic/transport/index.js.map +1 -0
  69. package/dist/nodes/vendors/OpenAi/actions/router.js +1 -1
  70. package/dist/nodes/vendors/OpenAi/actions/router.js.map +1 -1
  71. package/dist/types/credentials.json +1 -1
  72. package/dist/types/nodes.json +5 -4
  73. package/package.json +5 -4
@@ -0,0 +1,540 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var message_operation_exports = {};
30
+ __export(message_operation_exports, {
31
+ description: () => description,
32
+ execute: () => execute
33
+ });
34
+ module.exports = __toCommonJS(message_operation_exports);
35
+ var import_n8n_workflow = require("n8n-workflow");
36
+ var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
37
+ var import_helpers = require("../../../../../utils/helpers");
38
+ var import_utils = require("../../helpers/utils");
39
+ var import_transport = require("../../transport");
40
+ var import_descriptions = require("../descriptions");
41
+ const properties = [
42
+ import_descriptions.modelRLC,
43
+ {
44
+ displayName: "Messages",
45
+ name: "messages",
46
+ type: "fixedCollection",
47
+ typeOptions: {
48
+ sortable: true,
49
+ multipleValues: true
50
+ },
51
+ placeholder: "Add Message",
52
+ default: { values: [{ content: "", role: "user" }] },
53
+ options: [
54
+ {
55
+ displayName: "Values",
56
+ name: "values",
57
+ values: [
58
+ {
59
+ displayName: "Prompt",
60
+ name: "content",
61
+ type: "string",
62
+ description: "The content of the message to be sent",
63
+ default: "",
64
+ placeholder: "e.g. Hello, how can you help me?",
65
+ typeOptions: {
66
+ rows: 2
67
+ }
68
+ },
69
+ {
70
+ displayName: "Role",
71
+ name: "role",
72
+ type: "options",
73
+ description: "Role in shaping the model's response, it tells the model how it should behave and interact with the user",
74
+ options: [
75
+ {
76
+ name: "User",
77
+ value: "user",
78
+ description: "Send a message as a user and get a response from the model"
79
+ },
80
+ {
81
+ name: "Assistant",
82
+ value: "assistant",
83
+ description: "Tell the model to adopt a specific tone or personality"
84
+ }
85
+ ],
86
+ default: "user"
87
+ }
88
+ ]
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ displayName: "Add Attachments",
94
+ name: "addAttachments",
95
+ type: "boolean",
96
+ default: false,
97
+ description: "Whether to add attachments to the message"
98
+ },
99
+ {
100
+ displayName: "Attachments Input Type",
101
+ name: "attachmentsInputType",
102
+ type: "options",
103
+ default: "url",
104
+ description: "The type of input to use for the attachments",
105
+ options: [
106
+ {
107
+ name: "URL(s)",
108
+ value: "url"
109
+ },
110
+ {
111
+ name: "Binary File(s)",
112
+ value: "binary"
113
+ }
114
+ ],
115
+ displayOptions: {
116
+ show: {
117
+ addAttachments: [true]
118
+ }
119
+ }
120
+ },
121
+ {
122
+ displayName: "Attachment URL(s)",
123
+ name: "attachmentsUrls",
124
+ type: "string",
125
+ default: "",
126
+ placeholder: "e.g. https://example.com/image.png",
127
+ description: "URL(s) of the file(s) to attach, multiple URLs can be added separated by comma",
128
+ displayOptions: {
129
+ show: {
130
+ addAttachments: [true],
131
+ attachmentsInputType: ["url"]
132
+ }
133
+ }
134
+ },
135
+ {
136
+ displayName: "Attachment Input Data Field Name(s)",
137
+ name: "binaryPropertyName",
138
+ type: "string",
139
+ default: "data",
140
+ placeholder: "e.g. data",
141
+ description: "Name of the binary field(s) which contains the file(s) to attach, multiple field names can be added separated by comma",
142
+ displayOptions: {
143
+ show: {
144
+ addAttachments: [true],
145
+ attachmentsInputType: ["binary"]
146
+ }
147
+ }
148
+ },
149
+ {
150
+ displayName: "Simplify Output",
151
+ name: "simplify",
152
+ type: "boolean",
153
+ default: true,
154
+ description: "Whether to return a simplified version of the response instead of the raw data"
155
+ },
156
+ {
157
+ displayName: "Options",
158
+ name: "options",
159
+ placeholder: "Add Option",
160
+ type: "collection",
161
+ default: {},
162
+ options: [
163
+ {
164
+ displayName: "Include Merged Response",
165
+ name: "includeMergedResponse",
166
+ type: "boolean",
167
+ default: false,
168
+ description: "Whether to include a single output string merging all text parts of the response"
169
+ },
170
+ {
171
+ displayName: "System Message",
172
+ name: "system",
173
+ type: "string",
174
+ default: "",
175
+ placeholder: "e.g. You are a helpful assistant"
176
+ },
177
+ {
178
+ displayName: "Code Execution",
179
+ name: "codeExecution",
180
+ type: "boolean",
181
+ default: false,
182
+ description: "Whether to enable code execution. Not supported by all models."
183
+ },
184
+ {
185
+ displayName: "Web Search",
186
+ name: "webSearch",
187
+ type: "boolean",
188
+ default: false,
189
+ description: "Whether to enable web search"
190
+ },
191
+ {
192
+ displayName: "Web Search Max Uses",
193
+ name: "maxUses",
194
+ type: "number",
195
+ default: 5,
196
+ description: "The maximum number of web search uses per request",
197
+ typeOptions: {
198
+ minValue: 0,
199
+ numberPrecision: 0
200
+ }
201
+ },
202
+ {
203
+ displayName: "Web Search Allowed Domains",
204
+ name: "allowedDomains",
205
+ type: "string",
206
+ default: "",
207
+ description: 'Comma-separated list of domains to search. Only domains in this list will be searched. Conflicts with "Web Search Blocked Domains".',
208
+ placeholder: "e.g. google.com, wikipedia.org"
209
+ },
210
+ {
211
+ displayName: "Web Search Blocked Domains",
212
+ name: "blockedDomains",
213
+ type: "string",
214
+ default: "",
215
+ description: 'Comma-separated list of domains to block from search. Conflicts with "Web Search Allowed Domains".',
216
+ placeholder: "e.g. google.com, wikipedia.org"
217
+ },
218
+ {
219
+ displayName: "Maximum Number of Tokens",
220
+ name: "maxTokens",
221
+ default: 1024,
222
+ description: "The maximum number of tokens to generate in the completion",
223
+ type: "number",
224
+ typeOptions: {
225
+ minValue: 1,
226
+ numberPrecision: 0
227
+ }
228
+ },
229
+ {
230
+ displayName: "Output Randomness (Temperature)",
231
+ name: "temperature",
232
+ default: 1,
233
+ description: "Controls the randomness of the output. Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive",
234
+ type: "number",
235
+ typeOptions: {
236
+ minValue: 0,
237
+ maxValue: 1,
238
+ numberPrecision: 1
239
+ }
240
+ },
241
+ {
242
+ displayName: "Output Randomness (Top P)",
243
+ name: "topP",
244
+ default: 0.7,
245
+ description: "The maximum cumulative probability of tokens to consider when sampling",
246
+ type: "number",
247
+ typeOptions: {
248
+ minValue: 0,
249
+ maxValue: 1,
250
+ numberPrecision: 1
251
+ }
252
+ },
253
+ {
254
+ displayName: "Output Randomness (Top K)",
255
+ name: "topK",
256
+ default: 5,
257
+ description: "The maximum number of tokens to consider when sampling",
258
+ type: "number",
259
+ typeOptions: {
260
+ minValue: 0,
261
+ numberPrecision: 0
262
+ }
263
+ },
264
+ {
265
+ displayName: "Max Tool Calls Iterations",
266
+ name: "maxToolsIterations",
267
+ type: "number",
268
+ default: 15,
269
+ description: "The maximum number of tool iteration cycles the LLM will run before stopping. A single iteration can contain multiple tool calls. Set to 0 for no limit",
270
+ typeOptions: {
271
+ minValue: 0,
272
+ numberPrecision: 0
273
+ }
274
+ }
275
+ ]
276
+ }
277
+ ];
278
+ const displayOptions = {
279
+ show: {
280
+ operation: ["message"],
281
+ resource: ["text"]
282
+ }
283
+ };
284
+ const description = (0, import_n8n_workflow.updateDisplayOptions)(displayOptions, properties);
285
+ function getFileTypeOrThrow(mimeType) {
286
+ if (mimeType?.startsWith("image/")) {
287
+ return "image";
288
+ }
289
+ if (mimeType === "application/pdf") {
290
+ return "document";
291
+ }
292
+ throw new import_n8n_workflow.NodeOperationError(
293
+ this.getNode(),
294
+ `Unsupported file type: ${mimeType}. Only images and PDFs are supported.`
295
+ );
296
+ }
297
+ async function execute(i) {
298
+ const model = this.getNodeParameter("modelId", i, "", { extractValue: true });
299
+ const messages = this.getNodeParameter("messages.values", i, []);
300
+ const addAttachments = this.getNodeParameter("addAttachments", i, false);
301
+ const simplify = this.getNodeParameter("simplify", i, true);
302
+ const options = this.getNodeParameter("options", i, {});
303
+ const { tools, connectedTools } = await getTools.call(this, options);
304
+ if (addAttachments) {
305
+ if (options.codeExecution) {
306
+ await addCodeAttachmentsToMessages.call(this, i, messages);
307
+ } else {
308
+ await addRegularAttachmentsToMessages.call(this, i, messages);
309
+ }
310
+ }
311
+ const body = {
312
+ model,
313
+ messages,
314
+ tools,
315
+ max_tokens: options.maxTokens ?? 1024,
316
+ system: options.system,
317
+ temperature: options.temperature,
318
+ top_p: options.topP,
319
+ top_k: options.topK
320
+ };
321
+ let response = await import_transport.apiRequest.call(this, "POST", "/v1/messages", {
322
+ body,
323
+ enableAnthropicBetas: { codeExecution: options.codeExecution }
324
+ });
325
+ const maxToolsIterations = this.getNodeParameter("options.maxToolsIterations", i, 15);
326
+ const abortSignal = this.getExecutionCancelSignal();
327
+ let currentIteration = 0;
328
+ let pauseTurns = 0;
329
+ while (true) {
330
+ if (abortSignal?.aborted) {
331
+ break;
332
+ }
333
+ if (response.stop_reason === "tool_use") {
334
+ if (maxToolsIterations > 0 && currentIteration >= maxToolsIterations) {
335
+ break;
336
+ }
337
+ messages.push({
338
+ role: "assistant",
339
+ content: response.content
340
+ });
341
+ await handleToolUse.call(this, response, messages, connectedTools);
342
+ currentIteration++;
343
+ } else if (response.stop_reason === "pause_turn") {
344
+ if (pauseTurns >= 3) {
345
+ break;
346
+ }
347
+ messages.push({
348
+ role: "assistant",
349
+ content: response.content
350
+ });
351
+ pauseTurns++;
352
+ } else {
353
+ break;
354
+ }
355
+ response = await import_transport.apiRequest.call(this, "POST", "/v1/messages", {
356
+ body,
357
+ enableAnthropicBetas: { codeExecution: options.codeExecution }
358
+ });
359
+ }
360
+ const mergedResponse = options.includeMergedResponse ? response.content.filter((c) => c.type === "text").map((c) => c.text).join("") : void 0;
361
+ if (simplify) {
362
+ return [
363
+ {
364
+ json: {
365
+ content: response.content,
366
+ merged_response: mergedResponse
367
+ },
368
+ pairedItem: { item: i }
369
+ }
370
+ ];
371
+ }
372
+ return [
373
+ {
374
+ json: { ...response, merged_response: mergedResponse },
375
+ pairedItem: { item: i }
376
+ }
377
+ ];
378
+ }
379
+ async function getTools(options) {
380
+ let connectedTools = [];
381
+ const nodeInputs = this.getNodeInputs();
382
+ if (nodeInputs.some((i) => i.type === "ai_tool")) {
383
+ connectedTools = await (0, import_helpers.getConnectedTools)(this, true);
384
+ }
385
+ const tools = connectedTools.map((t) => ({
386
+ type: "custom",
387
+ name: t.name,
388
+ input_schema: (0, import_zod_to_json_schema.default)(t.schema),
389
+ description: t.description
390
+ }));
391
+ if (options.codeExecution) {
392
+ tools.push({
393
+ type: "code_execution_20250522",
394
+ name: "code_execution"
395
+ });
396
+ }
397
+ if (options.webSearch) {
398
+ const allowedDomains = options.allowedDomains ? (0, import_utils.splitByComma)(options.allowedDomains) : void 0;
399
+ const blockedDomains = options.blockedDomains ? (0, import_utils.splitByComma)(options.blockedDomains) : void 0;
400
+ tools.push({
401
+ type: "web_search_20250305",
402
+ name: "web_search",
403
+ max_uses: options.maxUses,
404
+ allowed_domains: allowedDomains,
405
+ blocked_domains: blockedDomains
406
+ });
407
+ }
408
+ return { tools, connectedTools };
409
+ }
410
+ async function addCodeAttachmentsToMessages(i, messages) {
411
+ const inputType = this.getNodeParameter("attachmentsInputType", i, "url");
412
+ const baseUrl = await import_utils.getBaseUrl.call(this);
413
+ const fileUrlPrefix = `${baseUrl}/v1/files/`;
414
+ let content;
415
+ if (inputType === "url") {
416
+ const urls = this.getNodeParameter("attachmentsUrls", i, "");
417
+ const promises = (0, import_utils.splitByComma)(urls).map(async (url) => {
418
+ if (url.startsWith(fileUrlPrefix)) {
419
+ return url.replace(fileUrlPrefix, "");
420
+ } else {
421
+ const { fileContent, mimeType } = await import_utils.downloadFile.call(this, url);
422
+ const response = await import_utils.uploadFile.call(this, fileContent, mimeType);
423
+ return response.id;
424
+ }
425
+ });
426
+ const fileIds = await Promise.all(promises);
427
+ content = fileIds.map((fileId) => ({
428
+ type: "container_upload",
429
+ file_id: fileId
430
+ }));
431
+ } else {
432
+ const binaryPropertyNames = this.getNodeParameter("binaryPropertyName", i, "data");
433
+ const promises = (0, import_utils.splitByComma)(binaryPropertyNames).map(async (binaryPropertyName) => {
434
+ const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
435
+ const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
436
+ const response = await import_utils.uploadFile.call(this, buffer, binaryData.mimeType);
437
+ return response.id;
438
+ });
439
+ const fileIds = await Promise.all(promises);
440
+ content = fileIds.map((fileId) => ({
441
+ type: "container_upload",
442
+ file_id: fileId
443
+ }));
444
+ }
445
+ messages.push({
446
+ role: "user",
447
+ content
448
+ });
449
+ }
450
+ async function addRegularAttachmentsToMessages(i, messages) {
451
+ const inputType = this.getNodeParameter("attachmentsInputType", i, "url");
452
+ const baseUrl = await import_utils.getBaseUrl.call(this);
453
+ const fileUrlPrefix = `${baseUrl}/v1/files/`;
454
+ let content;
455
+ if (inputType === "url") {
456
+ const urls = this.getNodeParameter("attachmentsUrls", i, "");
457
+ const promises = (0, import_utils.splitByComma)(urls).map(async (url) => {
458
+ if (url.startsWith(fileUrlPrefix)) {
459
+ const response = await import_transport.apiRequest.call(this, "GET", "", {
460
+ option: { url }
461
+ });
462
+ const type = getFileTypeOrThrow.call(this, response.mime_type);
463
+ return {
464
+ type,
465
+ source: {
466
+ type: "file",
467
+ file_id: url.replace(fileUrlPrefix, "")
468
+ }
469
+ };
470
+ } else {
471
+ const response = await this.helpers.httpRequest.call(this, {
472
+ url,
473
+ method: "HEAD",
474
+ returnFullResponse: true
475
+ });
476
+ const mimeType = (0, import_utils.getMimeType)(response.headers["content-type"]);
477
+ const type = getFileTypeOrThrow.call(this, mimeType);
478
+ return {
479
+ type,
480
+ source: {
481
+ type: "url",
482
+ url
483
+ }
484
+ };
485
+ }
486
+ });
487
+ content = await Promise.all(promises);
488
+ } else {
489
+ const binaryPropertyNames = this.getNodeParameter("binaryPropertyName", i, "data");
490
+ const promises = (0, import_utils.splitByComma)(binaryPropertyNames).map(async (binaryPropertyName) => {
491
+ const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
492
+ const type = getFileTypeOrThrow.call(this, binaryData.mimeType);
493
+ const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
494
+ const fileBase64 = buffer.toString("base64");
495
+ return {
496
+ type,
497
+ source: {
498
+ type: "base64",
499
+ media_type: binaryData.mimeType,
500
+ data: fileBase64
501
+ }
502
+ };
503
+ });
504
+ content = await Promise.all(promises);
505
+ }
506
+ messages.push({
507
+ role: "user",
508
+ content
509
+ });
510
+ }
511
+ async function handleToolUse(response, messages, connectedTools) {
512
+ const toolCalls = response.content.filter((c) => c.type === "tool_use");
513
+ if (!toolCalls.length) {
514
+ return;
515
+ }
516
+ const toolResults = {
517
+ role: "user",
518
+ content: []
519
+ };
520
+ for (const toolCall of toolCalls) {
521
+ let toolResponse;
522
+ for (const connectedTool of connectedTools) {
523
+ if (connectedTool.name === toolCall.name) {
524
+ toolResponse = await connectedTool.invoke(toolCall.input);
525
+ }
526
+ }
527
+ toolResults.content.push({
528
+ type: "tool_result",
529
+ tool_use_id: toolCall.id,
530
+ content: typeof toolResponse === "object" ? JSON.stringify(toolResponse) : toolResponse ?? ""
531
+ });
532
+ }
533
+ messages.push(toolResults);
534
+ }
535
+ // Annotate the CommonJS export names for ESM import in node:
536
+ 0 && (module.exports = {
537
+ description,
538
+ execute
539
+ });
540
+ //# sourceMappingURL=message.operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../nodes/vendors/Anthropic/actions/text/message.operation.ts"],"sourcesContent":["import type { Tool } from '@langchain/core/tools';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeProperties,\n} from 'n8n-workflow';\nimport { NodeOperationError, updateDisplayOptions } from 'n8n-workflow';\nimport zodToJsonSchema from 'zod-to-json-schema';\n\nimport { getConnectedTools } from '@utils/helpers';\n\nimport type {\n\tContent,\n\tFile,\n\tMessage,\n\tMessagesResponse,\n\tTool as AnthropicTool,\n} from '../../helpers/interfaces';\nimport {\n\tdownloadFile,\n\tgetBaseUrl,\n\tgetMimeType,\n\tsplitByComma,\n\tuploadFile,\n} from '../../helpers/utils';\nimport { apiRequest } from '../../transport';\nimport { modelRLC } from '../descriptions';\n\nconst properties: INodeProperties[] = [\n\tmodelRLC,\n\t{\n\t\tdisplayName: 'Messages',\n\t\tname: 'messages',\n\t\ttype: 'fixedCollection',\n\t\ttypeOptions: {\n\t\t\tsortable: true,\n\t\t\tmultipleValues: true,\n\t\t},\n\t\tplaceholder: 'Add Message',\n\t\tdefault: { values: [{ content: '', role: 'user' }] },\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Values',\n\t\t\t\tname: 'values',\n\t\t\t\tvalues: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\t\t\tname: 'content',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdescription: 'The content of the message to be sent',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 2,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Role',\n\t\t\t\t\t\tname: 'role',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Role in shaping the model's response, it tells the model how it should behave and interact with the user\",\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'User',\n\t\t\t\t\t\t\t\tvalue: 'user',\n\t\t\t\t\t\t\t\tdescription: 'Send a message as a user and get a response from the model',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Assistant',\n\t\t\t\t\t\t\t\tvalue: 'assistant',\n\t\t\t\t\t\t\t\tdescription: 'Tell the model to adopt a specific tone or personality',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'user',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tdisplayName: 'Add Attachments',\n\t\tname: 'addAttachments',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tdescription: 'Whether to add attachments to the message',\n\t},\n\t{\n\t\tdisplayName: 'Attachments Input Type',\n\t\tname: 'attachmentsInputType',\n\t\ttype: 'options',\n\t\tdefault: 'url',\n\t\tdescription: 'The type of input to use for the attachments',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'URL(s)',\n\t\t\t\tvalue: 'url',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Binary File(s)',\n\t\t\t\tvalue: 'binary',\n\t\t\t},\n\t\t],\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\taddAttachments: [true],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Attachment URL(s)',\n\t\tname: 'attachmentsUrls',\n\t\ttype: 'string',\n\t\tdefault: '',\n\t\tplaceholder: 'e.g. https://example.com/image.png',\n\t\tdescription: 'URL(s) of the file(s) to attach, multiple URLs can be added separated by comma',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\taddAttachments: [true],\n\t\t\t\tattachmentsInputType: ['url'],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Attachment Input Data Field Name(s)',\n\t\tname: 'binaryPropertyName',\n\t\ttype: 'string',\n\t\tdefault: 'data',\n\t\tplaceholder: 'e.g. data',\n\t\tdescription:\n\t\t\t'Name of the binary field(s) which contains the file(s) to attach, multiple field names can be added separated by comma',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\taddAttachments: [true],\n\t\t\t\tattachmentsInputType: ['binary'],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Simplify Output',\n\t\tname: 'simplify',\n\t\ttype: 'boolean',\n\t\tdefault: true,\n\t\tdescription: 'Whether to return a simplified version of the response instead of the raw data',\n\t},\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\tplaceholder: 'Add Option',\n\t\ttype: 'collection',\n\t\tdefault: {},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Include Merged Response',\n\t\t\t\tname: 'includeMergedResponse',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription:\n\t\t\t\t\t'Whether to include a single output string merging all text parts of the response',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'System Message',\n\t\t\t\tname: 'system',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. You are a helpful assistant',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Code Execution',\n\t\t\t\tname: 'codeExecution',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether to enable code execution. Not supported by all models.',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Web Search',\n\t\t\t\tname: 'webSearch',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether to enable web search',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Web Search Max Uses',\n\t\t\t\tname: 'maxUses',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 5,\n\t\t\t\tdescription: 'The maximum number of web search uses per request',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tminValue: 0,\n\t\t\t\t\tnumberPrecision: 0,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Web Search Allowed Domains',\n\t\t\t\tname: 'allowedDomains',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tdescription:\n\t\t\t\t\t'Comma-separated list of domains to search. Only domains in this list will be searched. Conflicts with \"Web Search Blocked Domains\".',\n\t\t\t\tplaceholder: 'e.g. google.com, wikipedia.org',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Web Search Blocked Domains',\n\t\t\t\tname: 'blockedDomains',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tdescription:\n\t\t\t\t\t'Comma-separated list of domains to block from search. Conflicts with \"Web Search Allowed Domains\".',\n\t\t\t\tplaceholder: 'e.g. google.com, wikipedia.org',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Maximum Number of Tokens',\n\t\t\t\tname: 'maxTokens',\n\t\t\t\tdefault: 1024,\n\t\t\t\tdescription: 'The maximum number of tokens to generate in the completion',\n\t\t\t\ttype: 'number',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tminValue: 1,\n\t\t\t\t\tnumberPrecision: 0,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Output Randomness (Temperature)',\n\t\t\t\tname: 'temperature',\n\t\t\t\tdefault: 1,\n\t\t\t\tdescription:\n\t\t\t\t\t'Controls the randomness of the output. Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive',\n\t\t\t\ttype: 'number',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tminValue: 0,\n\t\t\t\t\tmaxValue: 1,\n\t\t\t\t\tnumberPrecision: 1,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Output Randomness (Top P)',\n\t\t\t\tname: 'topP',\n\t\t\t\tdefault: 0.7,\n\t\t\t\tdescription: 'The maximum cumulative probability of tokens to consider when sampling',\n\t\t\t\ttype: 'number',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tminValue: 0,\n\t\t\t\t\tmaxValue: 1,\n\t\t\t\t\tnumberPrecision: 1,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Output Randomness (Top K)',\n\t\t\t\tname: 'topK',\n\t\t\t\tdefault: 5,\n\t\t\t\tdescription: 'The maximum number of tokens to consider when sampling',\n\t\t\t\ttype: 'number',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tminValue: 0,\n\t\t\t\t\tnumberPrecision: 0,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Max Tool Calls Iterations',\n\t\t\t\tname: 'maxToolsIterations',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 15,\n\t\t\t\tdescription:\n\t\t\t\t\t'The maximum number of tool iteration cycles the LLM will run before stopping. A single iteration can contain multiple tool calls. Set to 0 for no limit',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tminValue: 0,\n\t\t\t\t\tnumberPrecision: 0,\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n];\n\nconst displayOptions = {\n\tshow: {\n\t\toperation: ['message'],\n\t\tresource: ['text'],\n\t},\n};\n\nexport const description = updateDisplayOptions(displayOptions, properties);\n\ninterface MessageOptions {\n\tincludeMergedResponse?: boolean;\n\tcodeExecution?: boolean;\n\twebSearch?: boolean;\n\tallowedDomains?: string;\n\tblockedDomains?: string;\n\tmaxUses?: number;\n\tmaxTokens?: number;\n\tsystem?: string;\n\ttemperature?: number;\n\ttopP?: number;\n\ttopK?: number;\n}\n\nfunction getFileTypeOrThrow(this: IExecuteFunctions, mimeType?: string): 'image' | 'document' {\n\tif (mimeType?.startsWith('image/')) {\n\t\treturn 'image';\n\t}\n\n\tif (mimeType === 'application/pdf') {\n\t\treturn 'document';\n\t}\n\n\tthrow new NodeOperationError(\n\t\tthis.getNode(),\n\t\t`Unsupported file type: ${mimeType}. Only images and PDFs are supported.`,\n\t);\n}\n\nexport async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {\n\tconst model = this.getNodeParameter('modelId', i, '', { extractValue: true }) as string;\n\tconst messages = this.getNodeParameter('messages.values', i, []) as Message[];\n\tconst addAttachments = this.getNodeParameter('addAttachments', i, false) as boolean;\n\tconst simplify = this.getNodeParameter('simplify', i, true) as boolean;\n\tconst options = this.getNodeParameter('options', i, {}) as MessageOptions;\n\n\tconst { tools, connectedTools } = await getTools.call(this, options);\n\n\tif (addAttachments) {\n\t\tif (options.codeExecution) {\n\t\t\tawait addCodeAttachmentsToMessages.call(this, i, messages);\n\t\t} else {\n\t\t\tawait addRegularAttachmentsToMessages.call(this, i, messages);\n\t\t}\n\t}\n\n\tconst body = {\n\t\tmodel,\n\t\tmessages,\n\t\ttools,\n\t\tmax_tokens: options.maxTokens ?? 1024,\n\t\tsystem: options.system,\n\t\ttemperature: options.temperature,\n\t\ttop_p: options.topP,\n\t\ttop_k: options.topK,\n\t};\n\n\tlet response = (await apiRequest.call(this, 'POST', '/v1/messages', {\n\t\tbody,\n\t\tenableAnthropicBetas: { codeExecution: options.codeExecution },\n\t})) as MessagesResponse;\n\n\tconst maxToolsIterations = this.getNodeParameter('options.maxToolsIterations', i, 15) as number;\n\tconst abortSignal = this.getExecutionCancelSignal();\n\tlet currentIteration = 0;\n\tlet pauseTurns = 0;\n\twhile (true) {\n\t\tif (abortSignal?.aborted) {\n\t\t\tbreak;\n\t\t}\n\n\t\tif (response.stop_reason === 'tool_use') {\n\t\t\tif (maxToolsIterations > 0 && currentIteration >= maxToolsIterations) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tmessages.push({\n\t\t\t\trole: 'assistant',\n\t\t\t\tcontent: response.content,\n\t\t\t});\n\t\t\tawait handleToolUse.call(this, response, messages, connectedTools);\n\t\t\tcurrentIteration++;\n\t\t} else if (response.stop_reason === 'pause_turn') {\n\t\t\t// if the model has paused (can happen for the web search or code execution tool), we just retry 3 times\n\t\t\tif (pauseTurns >= 3) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tmessages.push({\n\t\t\t\trole: 'assistant',\n\t\t\t\tcontent: response.content,\n\t\t\t});\n\t\t\tpauseTurns++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\n\t\tresponse = (await apiRequest.call(this, 'POST', '/v1/messages', {\n\t\t\tbody,\n\t\t\tenableAnthropicBetas: { codeExecution: options.codeExecution },\n\t\t})) as MessagesResponse;\n\t}\n\n\tconst mergedResponse = options.includeMergedResponse\n\t\t? response.content\n\t\t\t\t.filter((c) => c.type === 'text')\n\t\t\t\t.map((c) => c.text)\n\t\t\t\t.join('')\n\t\t: undefined;\n\n\tif (simplify) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tjson: {\n\t\t\t\t\tcontent: response.content,\n\t\t\t\t\tmerged_response: mergedResponse,\n\t\t\t\t},\n\t\t\t\tpairedItem: { item: i },\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [\n\t\t{\n\t\t\tjson: { ...response, merged_response: mergedResponse },\n\t\t\tpairedItem: { item: i },\n\t\t},\n\t];\n}\n\nasync function getTools(this: IExecuteFunctions, options: MessageOptions) {\n\tlet connectedTools: Tool[] = [];\n\tconst nodeInputs = this.getNodeInputs();\n\t// the node can be used as a tool, in this case there won't be any connected tools\n\tif (nodeInputs.some((i) => i.type === 'ai_tool')) {\n\t\tconnectedTools = await getConnectedTools(this, true);\n\t}\n\n\tconst tools: AnthropicTool[] = connectedTools.map((t) => ({\n\t\ttype: 'custom',\n\t\tname: t.name,\n\t\tinput_schema: zodToJsonSchema(t.schema),\n\t\tdescription: t.description,\n\t}));\n\n\tif (options.codeExecution) {\n\t\ttools.push({\n\t\t\ttype: 'code_execution_20250522',\n\t\t\tname: 'code_execution',\n\t\t});\n\t}\n\n\tif (options.webSearch) {\n\t\tconst allowedDomains = options.allowedDomains\n\t\t\t? splitByComma(options.allowedDomains)\n\t\t\t: undefined;\n\t\tconst blockedDomains = options.blockedDomains\n\t\t\t? splitByComma(options.blockedDomains)\n\t\t\t: undefined;\n\t\ttools.push({\n\t\t\ttype: 'web_search_20250305',\n\t\t\tname: 'web_search',\n\t\t\tmax_uses: options.maxUses,\n\t\t\tallowed_domains: allowedDomains,\n\t\t\tblocked_domains: blockedDomains,\n\t\t});\n\t}\n\n\treturn { tools, connectedTools };\n}\n\nasync function addCodeAttachmentsToMessages(\n\tthis: IExecuteFunctions,\n\ti: number,\n\tmessages: Message[],\n) {\n\tconst inputType = this.getNodeParameter('attachmentsInputType', i, 'url') as string;\n\tconst baseUrl = await getBaseUrl.call(this);\n\tconst fileUrlPrefix = `${baseUrl}/v1/files/`;\n\n\tlet content: Content[];\n\tif (inputType === 'url') {\n\t\tconst urls = this.getNodeParameter('attachmentsUrls', i, '') as string;\n\t\tconst promises = splitByComma(urls).map(async (url) => {\n\t\t\tif (url.startsWith(fileUrlPrefix)) {\n\t\t\t\treturn url.replace(fileUrlPrefix, '');\n\t\t\t} else {\n\t\t\t\tconst { fileContent, mimeType } = await downloadFile.call(this, url);\n\t\t\t\tconst response = await uploadFile.call(this, fileContent, mimeType);\n\t\t\t\treturn response.id;\n\t\t\t}\n\t\t});\n\n\t\tconst fileIds = await Promise.all(promises);\n\t\tcontent = fileIds.map((fileId) => ({\n\t\t\ttype: 'container_upload',\n\t\t\tfile_id: fileId,\n\t\t}));\n\t} else {\n\t\tconst binaryPropertyNames = this.getNodeParameter('binaryPropertyName', i, 'data');\n\t\tconst promises = splitByComma(binaryPropertyNames).map(async (binaryPropertyName) => {\n\t\t\tconst binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);\n\t\t\tconst buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);\n\t\t\tconst response = await uploadFile.call(this, buffer, binaryData.mimeType);\n\t\t\treturn response.id;\n\t\t});\n\n\t\tconst fileIds = await Promise.all(promises);\n\t\tcontent = fileIds.map((fileId) => ({\n\t\t\ttype: 'container_upload',\n\t\t\tfile_id: fileId,\n\t\t}));\n\t}\n\n\tmessages.push({\n\t\trole: 'user',\n\t\tcontent,\n\t});\n}\n\nasync function addRegularAttachmentsToMessages(\n\tthis: IExecuteFunctions,\n\ti: number,\n\tmessages: Message[],\n) {\n\tconst inputType = this.getNodeParameter('attachmentsInputType', i, 'url') as string;\n\tconst baseUrl = await getBaseUrl.call(this);\n\tconst fileUrlPrefix = `${baseUrl}/v1/files/`;\n\n\tlet content: Content[];\n\tif (inputType === 'url') {\n\t\tconst urls = this.getNodeParameter('attachmentsUrls', i, '') as string;\n\t\tconst promises = splitByComma(urls).map(async (url) => {\n\t\t\tif (url.startsWith(fileUrlPrefix)) {\n\t\t\t\tconst response = (await apiRequest.call(this, 'GET', '', {\n\t\t\t\t\toption: { url },\n\t\t\t\t})) as File;\n\t\t\t\tconst type = getFileTypeOrThrow.call(this, response.mime_type);\n\t\t\t\treturn {\n\t\t\t\t\ttype,\n\t\t\t\t\tsource: {\n\t\t\t\t\t\ttype: 'file',\n\t\t\t\t\t\tfile_id: url.replace(fileUrlPrefix, ''),\n\t\t\t\t\t},\n\t\t\t\t} as Content;\n\t\t\t} else {\n\t\t\t\tconst response = (await this.helpers.httpRequest.call(this, {\n\t\t\t\t\turl,\n\t\t\t\t\tmethod: 'HEAD',\n\t\t\t\t\treturnFullResponse: true,\n\t\t\t\t})) as { headers: IDataObject };\n\t\t\t\tconst mimeType = getMimeType(response.headers['content-type'] as string);\n\t\t\t\tconst type = getFileTypeOrThrow.call(this, mimeType);\n\t\t\t\treturn {\n\t\t\t\t\ttype,\n\t\t\t\t\tsource: {\n\t\t\t\t\t\ttype: 'url',\n\t\t\t\t\t\turl,\n\t\t\t\t\t},\n\t\t\t\t} as Content;\n\t\t\t}\n\t\t});\n\n\t\tcontent = await Promise.all(promises);\n\t} else {\n\t\tconst binaryPropertyNames = this.getNodeParameter('binaryPropertyName', i, 'data');\n\t\tconst promises = splitByComma(binaryPropertyNames).map(async (binaryPropertyName) => {\n\t\t\tconst binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);\n\t\t\tconst type = getFileTypeOrThrow.call(this, binaryData.mimeType);\n\t\t\tconst buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);\n\t\t\tconst fileBase64 = buffer.toString('base64');\n\t\t\treturn {\n\t\t\t\ttype,\n\t\t\t\tsource: {\n\t\t\t\t\ttype: 'base64',\n\t\t\t\t\tmedia_type: binaryData.mimeType,\n\t\t\t\t\tdata: fileBase64,\n\t\t\t\t},\n\t\t\t} as Content;\n\t\t});\n\n\t\tcontent = await Promise.all(promises);\n\t}\n\n\tmessages.push({\n\t\trole: 'user',\n\t\tcontent,\n\t});\n}\n\nasync function handleToolUse(\n\tthis: IExecuteFunctions,\n\tresponse: MessagesResponse,\n\tmessages: Message[],\n\tconnectedTools: Tool[],\n) {\n\tconst toolCalls = response.content.filter((c) => c.type === 'tool_use');\n\tif (!toolCalls.length) {\n\t\treturn;\n\t}\n\n\tconst toolResults = {\n\t\trole: 'user' as const,\n\t\tcontent: [] as Content[],\n\t};\n\tfor (const toolCall of toolCalls) {\n\t\tlet toolResponse;\n\t\tfor (const connectedTool of connectedTools) {\n\t\t\tif (connectedTool.name === toolCall.name) {\n\t\t\t\ttoolResponse = (await connectedTool.invoke(toolCall.input)) as IDataObject;\n\t\t\t}\n\t\t}\n\n\t\ttoolResults.content.push({\n\t\t\ttype: 'tool_result',\n\t\t\ttool_use_id: toolCall.id,\n\t\t\tcontent:\n\t\t\t\ttypeof toolResponse === 'object' ? JSON.stringify(toolResponse) : (toolResponse ?? ''),\n\t\t});\n\t}\n\n\tmessages.push(toolResults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,0BAAyD;AACzD,gCAA4B;AAE5B,qBAAkC;AASlC,mBAMO;AACP,uBAA2B;AAC3B,0BAAyB;AAEzB,MAAM,aAAgC;AAAA,EACrC;AAAA,EACA;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,aAAa;AAAA,MACZ,UAA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