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 Tool_Parameters in input
145
+ // Check if AI Agent sent tool name in input
146
146
  const inputData = items[0]?.json;
147
- const aiToolParams = inputData?.Tool_Parameters;
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
- // Check if Tool_Parameters has browser_action field
152
- if (aiToolParams && typeof aiToolParams === 'object' && 'browser_action' in aiToolParams) {
153
- const browserAction = aiToolParams.browser_action;
154
- toolName = `browser_${browserAction}`;
155
- }
156
- else if (aiAction && typeof aiAction === 'string' && aiAction !== 'sendMessage') {
157
- // AI Agent sent action like "click", "open", etc - map to browser tool
158
- toolName = aiAction === 'open' ? 'browser_navigate' : `browser_${aiAction}`;
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 mode or no AI action
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
- // First check if AI Agent sent Tool_Parameters in input
174
- if (aiToolParams && typeof aiToolParams === 'object') {
175
- toolParams = aiToolParams;
163
+ const rawParams = this.getNodeParameter('toolParameters', 0);
164
+ if (rawParams === undefined || rawParams === null) {
165
+ toolParams = {};
176
166
  }
177
- else {
178
- // Fallback to manual toolParameters field
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
- try {
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
- // Ensure toolParams is an object
204
- if (typeof toolParams !== 'object' ||
205
- toolParams === null ||
206
- Array.isArray(toolParams)) {
207
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Tool parameters must be a JSON object');
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",