deepdebug-local-agent 0.3.7 ā 0.3.8
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.
- package/package.json +1 -1
- package/server.js +1 -138
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -557,7 +557,6 @@ app.use(cors({
|
|
|
557
557
|
// Cloud Run URLs (regex patterns)
|
|
558
558
|
/https:\/\/.*\.run\.app$/,
|
|
559
559
|
/https:\/\/.*\.web\.app$/,
|
|
560
|
-
// Production frontend
|
|
561
560
|
"https://deepdebug.ai",
|
|
562
561
|
"https://www.deepdebug.ai"
|
|
563
562
|
],
|
|
@@ -5083,126 +5082,10 @@ app.post("/workspace/:workspaceId/run", async (req, res) => {
|
|
|
5083
5082
|
}
|
|
5084
5083
|
});
|
|
5085
5084
|
|
|
5086
|
-
|
|
5087
|
-
// ============================================
|
|
5088
|
-
// š CLOUDFLARE TUNNEL - Auto-expose Local Agent
|
|
5089
|
-
// ============================================
|
|
5090
|
-
import { execFile, spawn } from 'child_process';
|
|
5091
|
-
import { createWriteStream } from 'fs';
|
|
5092
|
-
import { pipeline } from 'stream/promises';
|
|
5093
|
-
|
|
5094
|
-
async function startCloudflaredTunnel(port, gatewayUrl, apiKey, workspaceId) {
|
|
5095
|
-
const platform = process.platform;
|
|
5096
|
-
const arch = process.arch;
|
|
5097
|
-
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
5098
|
-
const deepdebugDir = path.join(homeDir, '.deepdebug');
|
|
5099
|
-
const binaryName = platform === 'win32' ? 'cloudflared.exe' : 'cloudflared';
|
|
5100
|
-
const binaryPath = path.join(deepdebugDir, binaryName);
|
|
5101
|
-
|
|
5102
|
-
// Download URL based on platform
|
|
5103
|
-
const downloadUrls = {
|
|
5104
|
-
'win32-x64': 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe',
|
|
5105
|
-
'darwin-x64': 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64',
|
|
5106
|
-
'darwin-arm64':'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-arm64',
|
|
5107
|
-
'linux-x64': 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64',
|
|
5108
|
-
'linux-arm64': 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64',
|
|
5109
|
-
};
|
|
5110
|
-
|
|
5111
|
-
const key = `${platform}-${arch}`;
|
|
5112
|
-
const downloadUrl = downloadUrls[key];
|
|
5113
|
-
|
|
5114
|
-
if (!downloadUrl) {
|
|
5115
|
-
console.warn(`ā ļø Cloudflared not available for platform: ${key}`);
|
|
5116
|
-
return null;
|
|
5117
|
-
}
|
|
5118
|
-
|
|
5119
|
-
// Download cloudflared if not present
|
|
5120
|
-
if (!fs.existsSync(binaryPath)) {
|
|
5121
|
-
console.log(`ā¬ļø Downloading cloudflared for ${key}...`);
|
|
5122
|
-
try {
|
|
5123
|
-
const res = await fetch(downloadUrl);
|
|
5124
|
-
if (!res.ok) throw new Error(`Download failed: ${res.status}`);
|
|
5125
|
-
await pipeline(res.body, createWriteStream(binaryPath));
|
|
5126
|
-
// Make executable on unix
|
|
5127
|
-
if (platform !== 'win32') {
|
|
5128
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
5129
|
-
}
|
|
5130
|
-
console.log(`ā
cloudflared downloaded to ${binaryPath}`);
|
|
5131
|
-
} catch (err) {
|
|
5132
|
-
console.warn(`ā ļø Failed to download cloudflared: ${err.message}`);
|
|
5133
|
-
return null;
|
|
5134
|
-
}
|
|
5135
|
-
}
|
|
5136
|
-
|
|
5137
|
-
// Start tunnel
|
|
5138
|
-
return new Promise((resolve) => {
|
|
5139
|
-
console.log(`š Starting Cloudflare tunnel on port ${port}...`);
|
|
5140
|
-
|
|
5141
|
-
const child = spawn(binaryPath, [
|
|
5142
|
-
'tunnel', '--url', `http://localhost:${port}`,
|
|
5143
|
-
'--no-autoupdate'
|
|
5144
|
-
], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
5145
|
-
|
|
5146
|
-
let tunnelUrl = null;
|
|
5147
|
-
const urlPattern = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/;
|
|
5148
|
-
|
|
5149
|
-
const handleOutput = async (data) => {
|
|
5150
|
-
const text = data.toString();
|
|
5151
|
-
const match = text.match(urlPattern);
|
|
5152
|
-
if (match && !tunnelUrl) {
|
|
5153
|
-
tunnelUrl = match[0];
|
|
5154
|
-
console.log(`\nš ====================================`);
|
|
5155
|
-
console.log(`š Tunnel URL: ${tunnelUrl}`);
|
|
5156
|
-
console.log(`š ====================================\n`);
|
|
5157
|
-
|
|
5158
|
-
// Register tunnel URL with Gateway
|
|
5159
|
-
if (gatewayUrl && apiKey && workspaceId) {
|
|
5160
|
-
try {
|
|
5161
|
-
const registerRes = await fetch(`${gatewayUrl}/api/v1/workspaces/${workspaceId}/agent-url`, {
|
|
5162
|
-
method: 'PUT',
|
|
5163
|
-
headers: {
|
|
5164
|
-
'Content-Type': 'application/json',
|
|
5165
|
-
'Authorization': `Bearer ${apiKey}`
|
|
5166
|
-
},
|
|
5167
|
-
body: JSON.stringify({ agentUrl: tunnelUrl })
|
|
5168
|
-
});
|
|
5169
|
-
if (registerRes.ok) {
|
|
5170
|
-
console.log(`ā
Agent URL registered with Gateway`);
|
|
5171
|
-
} else {
|
|
5172
|
-
console.warn(`ā ļø Failed to register agent URL: ${registerRes.status}`);
|
|
5173
|
-
}
|
|
5174
|
-
} catch (err) {
|
|
5175
|
-
console.warn(`ā ļø Could not register agent URL: ${err.message}`);
|
|
5176
|
-
}
|
|
5177
|
-
}
|
|
5178
|
-
resolve(tunnelUrl);
|
|
5179
|
-
}
|
|
5180
|
-
};
|
|
5181
|
-
|
|
5182
|
-
child.stdout.on('data', handleOutput);
|
|
5183
|
-
child.stderr.on('data', handleOutput);
|
|
5184
|
-
|
|
5185
|
-
child.on('exit', (code) => {
|
|
5186
|
-
if (!tunnelUrl) {
|
|
5187
|
-
console.warn(`ā ļø cloudflared exited with code ${code} before tunnel was established`);
|
|
5188
|
-
resolve(null);
|
|
5189
|
-
}
|
|
5190
|
-
});
|
|
5191
|
-
|
|
5192
|
-
// Timeout after 30 seconds
|
|
5193
|
-
setTimeout(() => {
|
|
5194
|
-
if (!tunnelUrl) {
|
|
5195
|
-
console.warn('ā ļø Cloudflare tunnel timeout - continuing without tunnel');
|
|
5196
|
-
resolve(null);
|
|
5197
|
-
}
|
|
5198
|
-
}, 30000);
|
|
5199
|
-
});
|
|
5200
|
-
}
|
|
5201
|
-
|
|
5202
5085
|
// ============================================
|
|
5203
5086
|
// START SERVER
|
|
5204
5087
|
// ============================================
|
|
5205
|
-
app.listen(PORT, '0.0.0.0',
|
|
5088
|
+
app.listen(PORT, '0.0.0.0', () => {
|
|
5206
5089
|
console.log(`\nš DeepDebug Local Agent listening on port ${PORT}`);
|
|
5207
5090
|
console.log(`š¦ Environment: ${process.env.NODE_ENV || 'development'}`);
|
|
5208
5091
|
console.log(`š¦ Process Manager initialized`);
|
|
@@ -5213,26 +5096,6 @@ app.listen(PORT, '0.0.0.0', async () => {
|
|
|
5213
5096
|
console.log(` Max Retries: ${aiEngine.maxRetries}`);
|
|
5214
5097
|
}
|
|
5215
5098
|
console.log(`\nš Ready to receive requests!\n`);
|
|
5216
|
-
|
|
5217
|
-
// š Auto-start Cloudflare Tunnel
|
|
5218
|
-
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
5219
|
-
const configPath = path.join(homeDir, '.deepdebug', 'config.json');
|
|
5220
|
-
let tunnelConfig = {};
|
|
5221
|
-
try {
|
|
5222
|
-
if (fs.existsSync(configPath)) {
|
|
5223
|
-
tunnelConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
5224
|
-
}
|
|
5225
|
-
} catch (e) {}
|
|
5226
|
-
|
|
5227
|
-
const gatewayUrl = tunnelConfig.gatewayUrl || process.env.GATEWAY_URL;
|
|
5228
|
-
const apiKey = tunnelConfig.apiKey || process.env.DEEPDEBUG_API_KEY;
|
|
5229
|
-
const workspaceId = tunnelConfig.workspaceId || process.env.WORKSPACE_ID;
|
|
5230
|
-
|
|
5231
|
-
if (process.env.DISABLE_TUNNEL !== 'true') {
|
|
5232
|
-
startCloudflaredTunnel(PORT, gatewayUrl, apiKey, workspaceId).catch(err => {
|
|
5233
|
-
console.warn(`ā ļø Tunnel error: ${err.message}`);
|
|
5234
|
-
});
|
|
5235
|
-
}
|
|
5236
5099
|
});
|
|
5237
5100
|
|
|
5238
5101
|
// Start MCP HTTP Bridge em paralelo (port 5056)
|