n8n-nodes-smart-browser-automation 1.6.3 → 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.
@@ -27,10 +27,36 @@ class SmartBrowserAutomation {
27
27
  ],
28
28
  usableAsTool: true,
29
29
  properties: [
30
+ {
31
+ displayName: 'Operation',
32
+ name: 'operation',
33
+ type: 'options',
34
+ noDataExpression: true,
35
+ options: [
36
+ {
37
+ name: 'Execute Tool',
38
+ value: 'executeTool',
39
+ description: 'Execute a browser automation tool',
40
+ action: 'Execute a tool',
41
+ },
42
+ {
43
+ name: 'List Tools',
44
+ value: 'listTools',
45
+ description: 'Get available tools with their schemas',
46
+ action: 'List available tools',
47
+ },
48
+ ],
49
+ default: 'executeTool',
50
+ },
30
51
  {
31
52
  displayName: 'CDP Endpoint Override',
32
53
  name: 'cdpOverride',
33
54
  type: 'string',
55
+ displayOptions: {
56
+ show: {
57
+ operation: ['executeTool'],
58
+ },
59
+ },
34
60
  default: '',
35
61
  placeholder: 'wss://gridnew.doingerp.com/devtools/...',
36
62
  description: 'Override CDP endpoint from credentials. Use this to connect to a specific browser instance.',
@@ -39,6 +65,11 @@ class SmartBrowserAutomation {
39
65
  displayName: 'Tool Name or ID',
40
66
  name: 'toolName',
41
67
  type: 'options',
68
+ displayOptions: {
69
+ show: {
70
+ operation: ['executeTool'],
71
+ },
72
+ },
42
73
  typeOptions: {
43
74
  loadOptionsMethod: 'getAvailableTools',
44
75
  },
@@ -49,6 +80,11 @@ class SmartBrowserAutomation {
49
80
  displayName: 'Tool Parameters',
50
81
  name: 'toolParameters',
51
82
  type: 'json',
83
+ displayOptions: {
84
+ show: {
85
+ operation: ['executeTool'],
86
+ },
87
+ },
52
88
  required: true,
53
89
  default: '{}',
54
90
  description: 'Parameters to pass to the browser tool in JSON format',
@@ -82,76 +118,88 @@ class SmartBrowserAutomation {
82
118
  const returnData = [];
83
119
  const credentials = await this.getCredentials('smartBrowserAutomationApi');
84
120
  const sessionManager = BrowserSessionManager_1.default.getInstance();
121
+ const operation = this.getNodeParameter('operation', 0);
122
+ // Handle List Tools operation
123
+ if (operation === 'listTools') {
124
+ try {
125
+ await sessionManager.initialize(credentials.mcpEndpoint, false, '');
126
+ const tools = await sessionManager.listTools();
127
+ returnData.push({
128
+ json: {
129
+ tools: tools.map((tool) => ({
130
+ name: tool.name,
131
+ description: tool.description || `Execute the ${tool.name} tool`,
132
+ schema: tool.inputSchema || { type: 'object', properties: {}, additionalProperties: false },
133
+ }))
134
+ },
135
+ });
136
+ return [returnData];
137
+ }
138
+ catch (error) {
139
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to list tools: ${error.message}`);
140
+ }
141
+ }
142
+ // Handle Execute Tool operation
85
143
  // Get CDP override or use from credentials
86
144
  const cdpOverride = this.getNodeParameter('cdpOverride', 0, '');
87
- // Check if AI Agent sent Tool_Parameters in input
145
+ // Check if AI Agent sent tool name in input
88
146
  const inputData = items[0]?.json;
89
- const aiToolParams = inputData?.Tool_Parameters;
90
- const aiAction = inputData?.action;
91
- // Determine tool name: prefer AI input, fallback to manual parameter
147
+ // Determine tool name and parameters
92
148
  let toolName;
93
- // Check if Tool_Parameters has browser_action field
94
- if (aiToolParams && typeof aiToolParams === 'object' && 'browser_action' in aiToolParams) {
95
- const browserAction = aiToolParams.browser_action;
96
- toolName = `browser_${browserAction}`;
97
- }
98
- else if (aiAction && typeof aiAction === 'string' && aiAction !== 'sendMessage') {
99
- // AI Agent sent action like "click", "open", etc - map to browser tool
100
- 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;
101
158
  }
102
159
  else {
103
- // Manual mode or no AI action
160
+ // Manual execution - use node parameters
104
161
  toolName = this.getNodeParameter('toolName', 0);
105
- }
106
- try {
107
- // Initialize session if not ready
108
- if (!sessionManager.isReady()) {
109
- const cdpUrl = cdpOverride || credentials.cdpEndpoint || '';
110
- await sessionManager.initialize(credentials.mcpEndpoint, !!cdpUrl, cdpUrl);
111
- }
112
- // Handle tool execution
113
- let toolParams;
114
162
  try {
115
- // First check if AI Agent sent Tool_Parameters in input
116
- if (aiToolParams && typeof aiToolParams === 'object') {
117
- toolParams = aiToolParams;
163
+ const rawParams = this.getNodeParameter('toolParameters', 0);
164
+ if (rawParams === undefined || rawParams === null) {
165
+ toolParams = {};
118
166
  }
119
- else {
120
- // Fallback to manual toolParameters field
121
- const rawParams = this.getNodeParameter('toolParameters', 0);
122
- if (rawParams === undefined || rawParams === null) {
167
+ else if (typeof rawParams === 'string') {
168
+ if (!rawParams || rawParams.trim() === '') {
123
169
  toolParams = {};
124
170
  }
125
- else if (typeof rawParams === 'string') {
126
- if (!rawParams || rawParams.trim() === '') {
127
- toolParams = {};
128
- }
129
- else {
130
- toolParams = JSON.parse(rawParams);
131
- }
132
- }
133
- else if (typeof rawParams === 'object') {
134
- toolParams = rawParams;
135
- }
136
171
  else {
137
- try {
138
- toolParams = JSON.parse(JSON.stringify(rawParams));
139
- }
140
- catch (parseError) {
141
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid parameter type: ${typeof rawParams}`);
142
- }
172
+ toolParams = JSON.parse(rawParams);
143
173
  }
144
174
  }
145
- // Ensure toolParams is an object
146
- if (typeof toolParams !== 'object' ||
147
- toolParams === null ||
148
- Array.isArray(toolParams)) {
149
- 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
+ }
150
185
  }
151
186
  }
152
187
  catch (error) {
153
188
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to parse tool parameters: ${error.message}. Make sure the parameters are valid JSON.`);
154
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
+ }
155
203
  // Special handling for browser_connect_cdp
156
204
  if (toolName === 'browser_connect_cdp') {
157
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.3",
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",