n8n-nodes-smart-browser-automation 1.6.26 → 1.6.27
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.
|
@@ -17,6 +17,15 @@ export declare function getSelectedTools({ mode, includeTools, excludeTools, too
|
|
|
17
17
|
export declare const getErrorDescriptionFromToolCall: (result: unknown) => string | undefined;
|
|
18
18
|
export declare const createCallTool: (name: string, client: Client, timeout: number, onError: (error: string) => void) => (args: IDataObject) => Promise<{} | null>;
|
|
19
19
|
export declare function mcpToolToDynamicTool(tool: McpTool, onCallTool: (args: any) => Promise<any>): Promise<DynamicStructuredTool>;
|
|
20
|
+
/**
|
|
21
|
+
* Wraps a DynamicStructuredTool to log its execution to the n8n AI Tool output.
|
|
22
|
+
* This ensures the user sees the tool input and output in the n8n UI.
|
|
23
|
+
*/
|
|
24
|
+
export declare function logWrapper(tool: DynamicStructuredTool, nodeCtx: {
|
|
25
|
+
addOutputData: Function;
|
|
26
|
+
addInputData: Function;
|
|
27
|
+
getNextRunIndex?: Function;
|
|
28
|
+
}): DynamicStructuredTool;
|
|
20
29
|
export declare class McpToolkit extends Toolkit {
|
|
21
30
|
tools: DynamicStructuredTool[];
|
|
22
31
|
constructor(tools: DynamicStructuredTool[]);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.McpToolkit = exports.createCallTool = exports.getErrorDescriptionFromToolCall = void 0;
|
|
4
4
|
exports.getSelectedTools = getSelectedTools;
|
|
5
5
|
exports.mcpToolToDynamicTool = mcpToolToDynamicTool;
|
|
6
|
+
exports.logWrapper = logWrapper;
|
|
6
7
|
const tools_1 = require("@langchain/core/tools");
|
|
7
8
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
8
9
|
const agents_1 = require("@langchain/classic/agents");
|
|
@@ -81,6 +82,63 @@ async function mcpToolToDynamicTool(tool, onCallTool) {
|
|
|
81
82
|
metadata: { isFromToolkit: true },
|
|
82
83
|
});
|
|
83
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Wraps a DynamicStructuredTool to log its execution to the n8n AI Tool output.
|
|
87
|
+
* This ensures the user sees the tool input and output in the n8n UI.
|
|
88
|
+
*/
|
|
89
|
+
function logWrapper(tool, nodeCtx) {
|
|
90
|
+
// Access internal properties safely via casting if needed
|
|
91
|
+
const toolAny = tool;
|
|
92
|
+
const originalFunc = toolAny.func;
|
|
93
|
+
toolAny.func = async (args) => {
|
|
94
|
+
const toolName = toolAny.name;
|
|
95
|
+
const input = {
|
|
96
|
+
tool: toolName,
|
|
97
|
+
arguments: args,
|
|
98
|
+
};
|
|
99
|
+
let runIndex = 0;
|
|
100
|
+
try {
|
|
101
|
+
// n8n type hack: try to get run index if available
|
|
102
|
+
runIndex = nodeCtx.getNextRunIndex?.() ?? 0;
|
|
103
|
+
}
|
|
104
|
+
catch { }
|
|
105
|
+
// Log Input
|
|
106
|
+
// 2 is the index for NodeConnectionTypes.AiTool usually, check your node definition
|
|
107
|
+
// In SmartBrowserAutomationTools, output[0] = AiTool, output[1] = Main.
|
|
108
|
+
// Wait, NodeConnectionTypes are strings "ai_tool", "main".
|
|
109
|
+
// The `addInputData` returns { index, runIndex }.
|
|
110
|
+
// We need to use the connection name or index.
|
|
111
|
+
// "ai_tool" is typically index 0 if listed first in outputs.
|
|
112
|
+
const { index } = nodeCtx.addInputData('ai_tool', [[{ json: input }]], runIndex);
|
|
113
|
+
try {
|
|
114
|
+
const result = await originalFunc(args);
|
|
115
|
+
const output = {
|
|
116
|
+
tool: toolName,
|
|
117
|
+
result: result,
|
|
118
|
+
};
|
|
119
|
+
// Log Output
|
|
120
|
+
// We wrap in [[ { json: ... } ]] because n8n expects INodeExecutionData[][]
|
|
121
|
+
nodeCtx.addOutputData('ai_tool', index, [[{ json: output }]]);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// Log Error
|
|
126
|
+
const errorOutput = {
|
|
127
|
+
tool: toolName,
|
|
128
|
+
error: error.message || String(error),
|
|
129
|
+
};
|
|
130
|
+
// Try to log error output
|
|
131
|
+
try {
|
|
132
|
+
nodeCtx.addOutputData('ai_tool', index, [[{ json: errorOutput }]]);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
console.error(`Failed to log error for tool ${toolName}`, e);
|
|
136
|
+
}
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return tool;
|
|
141
|
+
}
|
|
84
142
|
class McpToolkit extends agents_1.Toolkit {
|
|
85
143
|
tools;
|
|
86
144
|
constructor(tools) {
|