n8n-nodes-smart-browser-automation 1.6.10 → 1.6.12

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.
@@ -1,8 +1,39 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
4
- const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
5
- const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
6
37
  class BrowserSessionManager {
7
38
  static instance;
8
39
  mcpClient = null;
@@ -33,35 +64,45 @@ class BrowserSessionManager {
33
64
  this.mcpClient = new index_js_1.Client({ name: 'n8n-browser-automation', version: '1.0.0' }, { capabilities: {} });
34
65
  // Determine transport based on endpoint type
35
66
  const isUrl = mcpEndpoint.startsWith('http://') || mcpEndpoint.startsWith('https://');
67
+ const urlIsSse = isUrl && /(^|\/)sse\/?(\?|#|$)/i.test(new URL(mcpEndpoint).pathname);
36
68
  if (isUrl) {
37
- // Connect via SSE
38
- this.transport = new sse_js_1.SSEClientTransport(new URL(mcpEndpoint));
69
+ if (urlIsSse) {
70
+ // Connect via SSE
71
+ const { SSEClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/sse.js')));
72
+ this.transport = new SSEClientTransport(new URL(mcpEndpoint));
73
+ }
74
+ else {
75
+ // Connect via Streamable HTTP
76
+ const { StreamableHTTPClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/streamableHttp.js')));
77
+ this.transport = new StreamableHTTPClientTransport(new URL(mcpEndpoint));
78
+ }
39
79
  }
40
80
  else {
41
- // Connect via Stdio
42
- this.transport = new stdio_js_1.StdioClientTransport({
81
+ // Connect via Stdio (lazy import so environments that only use SSE don't need stdio deps)
82
+ const { StdioClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/stdio.js')));
83
+ this.transport = new StdioClientTransport({
43
84
  command: 'node',
44
85
  args: [mcpEndpoint],
45
86
  env: {
46
87
  ...process.env,
47
- ...(useCDP && cdpEndpoint ? { CDP_URL: cdpEndpoint } : {})
48
- }
88
+ ...(useCDP && cdpEndpoint ? { CDP_URL: cdpEndpoint } : {}),
89
+ },
49
90
  });
50
91
  }
51
92
  try {
52
93
  await this.mcpClient.connect(this.transport);
53
- // Stability delay for SSE connections to ensure pipe is fully open
94
+ // Stability delay for HTTP connections to ensure session is fully open
54
95
  // Remote servers often need a moment to register the session before accepting POST calls
55
96
  if (isUrl) {
56
97
  if (process.env.NODE_ENV !== 'production') {
57
- console.log(`[MCP] SSE Connected to ${mcpEndpoint}. Waiting for session stabilization...`);
98
+ console.log(`[MCP] Connected to ${mcpEndpoint}. Waiting for session stabilization...`);
58
99
  }
59
100
  await new Promise(resolve => setTimeout(resolve, 2000));
60
101
  }
61
102
  }
62
103
  catch (error) {
63
104
  this.isInitialized = false;
64
- const transportType = isUrl ? 'SSE' : 'Stdio';
105
+ const transportType = isUrl ? (urlIsSse ? 'SSE' : 'Streamable HTTP') : 'Stdio';
65
106
  throw new Error(`Failed to connect to MCP server via ${transportType} at ${mcpEndpoint}. Error: ${error.message}`);
66
107
  }
67
108
  this.isInitialized = true;
@@ -42,6 +42,24 @@ exports.SmartBrowserAutomationTools = void 0;
42
42
  const n8n_workflow_1 = require("n8n-workflow");
43
43
  const BrowserSessionManager_1 = __importDefault(require("./BrowserSessionManager"));
44
44
  const jsonSchemaToZod_1 = require("./jsonSchemaToZod");
45
+ async function importDynamicStructuredTool() {
46
+ try {
47
+ return await Promise.resolve().then(() => __importStar(require('langchain/tools')));
48
+ }
49
+ catch {
50
+ // Some n8n installations ship a langchain build where subpath exports differ.
51
+ return await Promise.resolve().then(() => __importStar(require('@langchain/core/tools')));
52
+ }
53
+ }
54
+ async function importToolkitBase() {
55
+ try {
56
+ return await Promise.resolve().then(() => __importStar(require('langchain/agents')));
57
+ }
58
+ catch {
59
+ // Fallback: older/newer builds might export Toolkit elsewhere; keep as a last resort.
60
+ return await Promise.resolve().then(() => __importStar(require('langchain/agents')));
61
+ }
62
+ }
45
63
  class SmartBrowserAutomationTools {
46
64
  description = {
47
65
  displayName: 'Smart Browser Automation Tools',
@@ -91,8 +109,8 @@ class SmartBrowserAutomationTools {
91
109
  if (!mcpTools.length) {
92
110
  throw new n8n_workflow_1.NodeOperationError(node, 'MCP Server returned no tools', { itemIndex });
93
111
  }
94
- const { DynamicStructuredTool } = await Promise.resolve().then(() => __importStar(require('langchain/tools')));
95
- const { Toolkit } = await Promise.resolve().then(() => __importStar(require('langchain/agents')));
112
+ const { DynamicStructuredTool } = await importDynamicStructuredTool();
113
+ const { Toolkit } = await importToolkitBase();
96
114
  const tools = await Promise.all(mcpTools.map(async (tool) => {
97
115
  const schema = await (0, jsonSchemaToZod_1.jsonSchemaToZod)(tool.inputSchema);
98
116
  return new DynamicStructuredTool({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.6.10",
3
+ "version": "1.6.12",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",