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-T_SLBdOH.mjs');
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-D8bLCX8i.mjs').catch(() => ({ default: { version: "unknown" } }));
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-DTyspats.mjs');
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-DTyspats.mjs');
315
+ const { runTunnel } = await import('./tunnel-CtPReHFY.mjs');
316
316
  await runTunnel(name, ports);
317
317
  }
318
318
  async function handleServiceCommand() {
@@ -1,5 +1,5 @@
1
1
  var name = "svamp-cli";
2
- var version = "0.1.61";
2
+ var version = "0.1.62";
3
3
  var description = "Svamp CLI — AI workspace daemon on Hypha Cloud";
4
4
  var author = "Amun AI AB";
5
5
  var license = "SEE LICENSE IN LICENSE";
@@ -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
- delete forwardHeaders["accept-encoding"];
131
- delete forwardHeaders["Accept-Encoding"];
132
- const init = {
133
- method: req.method,
134
- headers: forwardHeaders,
135
- signal: controller.signal
136
- };
137
- if (req.body && !["GET", "HEAD"].includes(req.method.toUpperCase())) {
138
- init.body = Buffer.from(req.body, "base64");
139
- }
140
- try {
141
- const res = await fetch(url, init);
142
- clearTimeout(timeout);
143
- const bodyBuffer = await res.arrayBuffer();
144
- const bodyBase64 = bodyBuffer.byteLength > 0 ? Buffer.from(bodyBuffer).toString("base64") : void 0;
145
- const headers = {};
146
- res.headers.forEach((value, key) => {
147
- if (key === "content-encoding" || key === "content-length") return;
148
- headers[key] = value;
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: res.status,
154
- headers,
176
+ status: status_holder.status,
177
+ headers: status_holder.headers,
155
178
  body: bodyBase64
156
179
  });
157
- } catch (err) {
158
- clearTimeout(timeout);
159
- if (err.name === "AbortError") {
160
- this.send({
161
- type: "response",
162
- id: req.id,
163
- status: 504,
164
- headers: { "content-type": "text/plain" },
165
- body: Buffer.from("Tunnel: request timeout").toString("base64")
166
- });
167
- } else {
168
- this.send({
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svamp-cli",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "description": "Svamp CLI — AI workspace daemon on Hypha Cloud",
5
5
  "author": "Amun AI AB",
6
6
  "license": "SEE LICENSE IN LICENSE",