svamp-cli 0.1.61 → 0.1.62
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/dist/cli.mjs
CHANGED
|
@@ -106,7 +106,7 @@ async function main() {
|
|
|
106
106
|
} else if (subcommand === "skills") {
|
|
107
107
|
await handleSkillsCommand();
|
|
108
108
|
} else if (subcommand === "service" || subcommand === "svc") {
|
|
109
|
-
const { handleServiceCommand } = await import('./commands-
|
|
109
|
+
const { handleServiceCommand } = await import('./commands-DXia-6W4.mjs');
|
|
110
110
|
await handleServiceCommand();
|
|
111
111
|
} else if (subcommand === "process" || subcommand === "proc") {
|
|
112
112
|
const { processCommand } = await import('./commands-DTNg_sCX.mjs');
|
|
@@ -127,7 +127,7 @@ async function main() {
|
|
|
127
127
|
} else if (!subcommand || subcommand === "start") {
|
|
128
128
|
await handleInteractiveCommand();
|
|
129
129
|
} else if (subcommand === "--version" || subcommand === "-v") {
|
|
130
|
-
const pkg = await import('./package-
|
|
130
|
+
const pkg = await import('./package-BYxU0Wzp.mjs').catch(() => ({ default: { version: "unknown" } }));
|
|
131
131
|
console.log(`svamp version: ${pkg.default.version}`);
|
|
132
132
|
} else {
|
|
133
133
|
console.error(`Unknown command: ${subcommand}`);
|
|
@@ -296,7 +296,7 @@ Service is live:`);
|
|
|
296
296
|
}
|
|
297
297
|
} else {
|
|
298
298
|
console.log(`No SANDBOX_ID detected \u2014 starting reverse tunnel.`);
|
|
299
|
-
const { runTunnel } = await import('./tunnel-
|
|
299
|
+
const { runTunnel } = await import('./tunnel-CtPReHFY.mjs');
|
|
300
300
|
await runTunnel(name, ports);
|
|
301
301
|
}
|
|
302
302
|
} catch (err) {
|
|
@@ -312,7 +312,7 @@ async function serviceTunnel(args) {
|
|
|
312
312
|
console.error("Usage: svamp service tunnel <name> --port <port> [--port <port2>]");
|
|
313
313
|
process.exit(1);
|
|
314
314
|
}
|
|
315
|
-
const { runTunnel } = await import('./tunnel-
|
|
315
|
+
const { runTunnel } = await import('./tunnel-CtPReHFY.mjs');
|
|
316
316
|
await runTunnel(name, ports);
|
|
317
317
|
}
|
|
318
318
|
async function handleServiceCommand() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as os from 'os';
|
|
2
|
+
import * as http from 'http';
|
|
2
3
|
import { requireSandboxApiEnv } from './api-Cegey1dh.mjs';
|
|
3
4
|
import { WebSocket } from 'ws';
|
|
4
5
|
|
|
@@ -123,57 +124,71 @@ class TunnelClient {
|
|
|
123
124
|
async proxyRequest(req) {
|
|
124
125
|
this.requestCount++;
|
|
125
126
|
const port = req.port || this.options.ports[0];
|
|
126
|
-
const url = `http://${this.options.localHost}:${port}${req.path}`;
|
|
127
|
-
const controller = new AbortController();
|
|
128
|
-
const timeout = setTimeout(() => controller.abort(), this.options.requestTimeout);
|
|
129
127
|
const forwardHeaders = { ...req.headers };
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
128
|
+
const chunks = [];
|
|
129
|
+
const status_holder = { status: 502, headers: {} };
|
|
130
|
+
await new Promise((resolve, reject) => {
|
|
131
|
+
const timeout = setTimeout(() => reject(new Error("timeout")), this.options.requestTimeout);
|
|
132
|
+
const options = {
|
|
133
|
+
hostname: this.options.localHost,
|
|
134
|
+
port,
|
|
135
|
+
path: req.path,
|
|
136
|
+
method: req.method,
|
|
137
|
+
headers: forwardHeaders
|
|
138
|
+
};
|
|
139
|
+
const httpReq = http.request(options, (res) => {
|
|
140
|
+
status_holder.status = res.statusCode ?? 502;
|
|
141
|
+
const rawHeaders = res.headers;
|
|
142
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
status_holder.headers[key] = value.join(", ");
|
|
145
|
+
} else if (value !== void 0) {
|
|
146
|
+
status_holder.headers[key] = value;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
150
|
+
res.on("end", () => {
|
|
151
|
+
clearTimeout(timeout);
|
|
152
|
+
resolve();
|
|
153
|
+
});
|
|
154
|
+
res.on("error", (e) => {
|
|
155
|
+
clearTimeout(timeout);
|
|
156
|
+
reject(e);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
httpReq.on("error", (e) => {
|
|
160
|
+
clearTimeout(timeout);
|
|
161
|
+
reject(e);
|
|
149
162
|
});
|
|
163
|
+
if (req.body && !["GET", "HEAD"].includes(req.method.toUpperCase())) {
|
|
164
|
+
httpReq.write(Buffer.from(req.body, "base64"));
|
|
165
|
+
}
|
|
166
|
+
httpReq.end();
|
|
167
|
+
}).then(() => {
|
|
168
|
+
const bodyBuffer = Buffer.concat(chunks);
|
|
169
|
+
const bodyBase64 = bodyBuffer.length > 0 ? bodyBuffer.toString("base64") : void 0;
|
|
170
|
+
for (const h of ["connection", "keep-alive", "transfer-encoding"]) {
|
|
171
|
+
delete status_holder.headers[h];
|
|
172
|
+
}
|
|
150
173
|
this.send({
|
|
151
174
|
type: "response",
|
|
152
175
|
id: req.id,
|
|
153
|
-
status:
|
|
154
|
-
headers,
|
|
176
|
+
status: status_holder.status,
|
|
177
|
+
headers: status_holder.headers,
|
|
155
178
|
body: bodyBase64
|
|
156
179
|
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
type: "response",
|
|
170
|
-
id: req.id,
|
|
171
|
-
status: 502,
|
|
172
|
-
headers: { "content-type": "text/plain" },
|
|
173
|
-
body: Buffer.from(`Tunnel: local service error: ${err.message}`).toString("base64")
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
180
|
+
}).catch((err) => {
|
|
181
|
+
const isTimeout = err.message === "timeout";
|
|
182
|
+
this.send({
|
|
183
|
+
type: "response",
|
|
184
|
+
id: req.id,
|
|
185
|
+
status: isTimeout ? 504 : 502,
|
|
186
|
+
headers: { "content-type": "text/plain" },
|
|
187
|
+
body: Buffer.from(
|
|
188
|
+
isTimeout ? "Tunnel: request timeout" : `Tunnel: local service error: ${err.message}`
|
|
189
|
+
).toString("base64")
|
|
190
|
+
});
|
|
191
|
+
});
|
|
177
192
|
}
|
|
178
193
|
// ── WebSocket proxying ───────────────────────────────────────────────
|
|
179
194
|
async handleWsOpen(msg) {
|