n8n-nodes-smart-browser-automation 1.6.4 → 1.6.5
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.
|
@@ -142,74 +142,64 @@ class SmartBrowserAutomation {
|
|
|
142
142
|
// Handle Execute Tool operation
|
|
143
143
|
// Get CDP override or use from credentials
|
|
144
144
|
const cdpOverride = this.getNodeParameter('cdpOverride', 0, '');
|
|
145
|
-
// Check if AI Agent sent
|
|
145
|
+
// Check if AI Agent sent tool name in input
|
|
146
146
|
const inputData = items[0]?.json;
|
|
147
|
-
|
|
148
|
-
const aiAction = inputData?.action;
|
|
149
|
-
// Determine tool name: prefer AI input, fallback to manual parameter
|
|
147
|
+
// Determine tool name and parameters
|
|
150
148
|
let toolName;
|
|
151
|
-
|
|
152
|
-
if
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
149
|
+
let toolParams;
|
|
150
|
+
// Check if this is from AI Agent (has 'tool' field in json)
|
|
151
|
+
if (inputData?.tool && typeof inputData.tool === 'string') {
|
|
152
|
+
// AI Agent execution - tool name is in item.json.tool
|
|
153
|
+
toolName = inputData.tool;
|
|
154
|
+
// Extract parameters by removing known n8n/AI fields
|
|
155
|
+
const { tool, action, chatInput, sessionId, toolCallId, name, id, arguments: args, ...rest } = inputData;
|
|
156
|
+
// Use 'arguments' field if present, otherwise use remaining fields
|
|
157
|
+
toolParams = args && typeof args === 'object' ? args : rest;
|
|
159
158
|
}
|
|
160
159
|
else {
|
|
161
|
-
// Manual
|
|
160
|
+
// Manual execution - use node parameters
|
|
162
161
|
toolName = this.getNodeParameter('toolName', 0);
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
// Initialize session if not ready
|
|
166
|
-
if (!sessionManager.isReady()) {
|
|
167
|
-
const cdpUrl = cdpOverride || credentials.cdpEndpoint || '';
|
|
168
|
-
await sessionManager.initialize(credentials.mcpEndpoint, !!cdpUrl, cdpUrl);
|
|
169
|
-
}
|
|
170
|
-
// Handle tool execution
|
|
171
|
-
let toolParams;
|
|
172
162
|
try {
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
toolParams =
|
|
163
|
+
const rawParams = this.getNodeParameter('toolParameters', 0);
|
|
164
|
+
if (rawParams === undefined || rawParams === null) {
|
|
165
|
+
toolParams = {};
|
|
176
166
|
}
|
|
177
|
-
else {
|
|
178
|
-
|
|
179
|
-
const rawParams = this.getNodeParameter('toolParameters', 0);
|
|
180
|
-
if (rawParams === undefined || rawParams === null) {
|
|
167
|
+
else if (typeof rawParams === 'string') {
|
|
168
|
+
if (!rawParams || rawParams.trim() === '') {
|
|
181
169
|
toolParams = {};
|
|
182
170
|
}
|
|
183
|
-
else if (typeof rawParams === 'string') {
|
|
184
|
-
if (!rawParams || rawParams.trim() === '') {
|
|
185
|
-
toolParams = {};
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
toolParams = JSON.parse(rawParams);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else if (typeof rawParams === 'object') {
|
|
192
|
-
toolParams = rawParams;
|
|
193
|
-
}
|
|
194
171
|
else {
|
|
195
|
-
|
|
196
|
-
toolParams = JSON.parse(JSON.stringify(rawParams));
|
|
197
|
-
}
|
|
198
|
-
catch (parseError) {
|
|
199
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid parameter type: ${typeof rawParams}`);
|
|
200
|
-
}
|
|
172
|
+
toolParams = JSON.parse(rawParams);
|
|
201
173
|
}
|
|
202
174
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
175
|
+
else if (typeof rawParams === 'object') {
|
|
176
|
+
toolParams = rawParams;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
try {
|
|
180
|
+
toolParams = JSON.parse(JSON.stringify(rawParams));
|
|
181
|
+
}
|
|
182
|
+
catch (parseError) {
|
|
183
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid parameter type: ${typeof rawParams}`);
|
|
184
|
+
}
|
|
208
185
|
}
|
|
209
186
|
}
|
|
210
187
|
catch (error) {
|
|
211
188
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to parse tool parameters: ${error.message}. Make sure the parameters are valid JSON.`);
|
|
212
189
|
}
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
// Initialize session if not ready
|
|
193
|
+
if (!sessionManager.isReady()) {
|
|
194
|
+
const cdpUrl = cdpOverride || credentials.cdpEndpoint || '';
|
|
195
|
+
await sessionManager.initialize(credentials.mcpEndpoint, !!cdpUrl, cdpUrl);
|
|
196
|
+
}
|
|
197
|
+
// Ensure toolParams is an object
|
|
198
|
+
if (typeof toolParams !== 'object' ||
|
|
199
|
+
toolParams === null ||
|
|
200
|
+
Array.isArray(toolParams)) {
|
|
201
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Tool parameters must be a JSON object');
|
|
202
|
+
}
|
|
213
203
|
// Special handling for browser_connect_cdp
|
|
214
204
|
if (toolName === 'browser_connect_cdp') {
|
|
215
205
|
const endpoint = toolParams.endpoint || cdpOverride || credentials.cdpEndpoint;
|