viagen 0.0.36 → 0.0.37

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.js CHANGED
@@ -44,6 +44,16 @@ function extractHost(httpsUrl) {
44
44
  return "github.com";
45
45
  }
46
46
  }
47
+ function startDots(label) {
48
+ process.stdout.write(label);
49
+ const timer = setInterval(() => process.stdout.write("."), 1e3);
50
+ return {
51
+ stop() {
52
+ clearInterval(timer);
53
+ process.stdout.write("\n");
54
+ }
55
+ };
56
+ }
47
57
  async function waitForServer(baseUrl, devServer) {
48
58
  const timeout = 6e4;
49
59
  const start = Date.now();
@@ -52,13 +62,7 @@ async function waitForServer(baseUrl, devServer) {
52
62
  const logStream = (async () => {
53
63
  try {
54
64
  for await (const log of devServer.logs({ signal: ac.signal })) {
55
- const line = log.data;
56
- serverOutput += line;
57
- if (log.stream === "stderr") {
58
- process.stderr.write(` ${line}`);
59
- } else {
60
- process.stdout.write(` ${line}`);
61
- }
65
+ serverOutput += log.data;
62
66
  }
63
67
  } catch {
64
68
  }
@@ -212,14 +216,12 @@ async function deploySandbox(opts) {
212
216
  content: Buffer.from(envLines.join("\n"))
213
217
  }
214
218
  ]);
215
- console.log(" Installing dependencies...");
216
- const install = await sandbox2.runCommand({
217
- cmd: "npm",
218
- args: ["install"],
219
- stdout: process.stdout,
220
- stderr: process.stderr
221
- });
219
+ const dots = startDots(" Installing dependencies");
220
+ const install = await sandbox2.runCommand("npm", ["install"]);
221
+ dots.stop();
222
222
  if (install.exitCode !== 0) {
223
+ const stderr = await install.stderr();
224
+ console.error(stderr);
223
225
  throw new Error(`npm install failed (exit ${install.exitCode})`);
224
226
  }
225
227
  const devServer = await sandbox2.runCommand({
@@ -227,10 +229,11 @@ async function deploySandbox(opts) {
227
229
  args: ["run", "dev", "--", "--host", "0.0.0.0"],
228
230
  detached: true
229
231
  });
230
- console.log(" Starting dev server...");
231
232
  const baseUrl = sandbox2.domain(5173);
232
233
  const url = `${baseUrl}/t/${token}`;
234
+ const dots2 = startDots(" Starting dev server");
233
235
  const ready = await waitForServer(baseUrl, devServer);
236
+ dots2.stop();
234
237
  if (!ready.ok) {
235
238
  throw new Error(
236
239
  `Dev server failed to start: ${ready.error}`
@@ -240,7 +243,9 @@ async function deploySandbox(opts) {
240
243
  url,
241
244
  token,
242
245
  sandboxId: sandbox2.sandboxId,
243
- mode: useGit ? "git" : "upload"
246
+ mode: useGit ? "git" : "upload",
247
+ streamLogs: (opts2) => devServer.logs(opts2),
248
+ stop: () => sandbox2.stop()
244
249
  };
245
250
  } catch (err) {
246
251
  await sandbox2.stop().catch(() => {
@@ -1054,11 +1059,15 @@ async function sandbox(args, options) {
1054
1059
  }
1055
1060
  }
1056
1061
  console.log("");
1057
- console.log("Creating sandbox...");
1058
1062
  if (deployGit) {
1059
1063
  console.log(` Repo: ${deployGit.remoteUrl}`);
1060
1064
  console.log(` Branch: ${deployGit.branch}`);
1061
1065
  }
1066
+ const frames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
1067
+ let frameIdx = 0;
1068
+ const spinner = setInterval(() => {
1069
+ process.stdout.write(`\r ${frames[frameIdx++ % frames.length]} Creating sandbox...`);
1070
+ }, 80);
1062
1071
  const result = await deploySandbox({
1063
1072
  cwd,
1064
1073
  apiKey: hasApiKey ? env["ANTHROPIC_API_KEY"] : void 0,
@@ -1078,13 +1087,13 @@ async function sandbox(args, options) {
1078
1087
  timeoutMinutes,
1079
1088
  prompt
1080
1089
  });
1090
+ clearInterval(spinner);
1091
+ process.stdout.write("\r \u2713 Sandbox ready! \n");
1081
1092
  const baseUrl = result.url.replace(/\/t\/.*$/, "");
1082
1093
  const iframeUrl = `${baseUrl}/via/iframe/t/${result.token}`;
1083
1094
  const chatUrl = `${baseUrl}/via/ui/t/${result.token}`;
1084
1095
  const popUrl = `${baseUrl}/via/pop/t/${result.token}`;
1085
1096
  console.log("");
1086
- console.log("Sandbox deployed!");
1087
- console.log("");
1088
1097
  console.log(` App: ${result.url}`);
1089
1098
  console.log(` App + Chat: ${popUrl}`);
1090
1099
  console.log(` Split view: ${iframeUrl}`);
@@ -1095,9 +1104,36 @@ async function sandbox(args, options) {
1095
1104
  ` Mode: ${result.mode === "git" ? "git clone (can push)" : "file upload (ephemeral)"}`
1096
1105
  );
1097
1106
  console.log(` Timeout: ${timeoutMinutes ?? 30} minutes`);
1098
- console.log("");
1099
- console.log(`Stop with: npx viagen sandbox stop ${result.sandboxId}`);
1100
1107
  openBrowser2(iframeUrl);
1108
+ console.log("");
1109
+ console.log(" Streaming sandbox logs (Ctrl+C to stop)...");
1110
+ console.log("");
1111
+ const ac = new AbortController();
1112
+ const cleanup = async () => {
1113
+ ac.abort();
1114
+ console.log("");
1115
+ console.log("Stopping sandbox...");
1116
+ await result.stop().catch(() => {
1117
+ });
1118
+ console.log("Sandbox stopped.");
1119
+ process.exit(0);
1120
+ };
1121
+ process.on("SIGINT", () => {
1122
+ cleanup();
1123
+ });
1124
+ process.on("SIGTERM", () => {
1125
+ cleanup();
1126
+ });
1127
+ try {
1128
+ for await (const log of result.streamLogs({ signal: ac.signal })) {
1129
+ if (log.stream === "stderr") {
1130
+ process.stderr.write(log.data);
1131
+ } else {
1132
+ process.stdout.write(log.data);
1133
+ }
1134
+ }
1135
+ } catch {
1136
+ }
1101
1137
  }
1102
1138
  var SYNC_DENY_KEYS = /* @__PURE__ */ new Set([
1103
1139
  "VIAGEN_PROJECT_ID",
package/dist/index.d.ts CHANGED
@@ -56,6 +56,15 @@ interface DeploySandboxResult {
56
56
  sandboxId: string;
57
57
  /** Deployment mode used. */
58
58
  mode: "git" | "upload";
59
+ /** Stream dev server logs. Yields { data, stream } entries. Call close() to stop. */
60
+ streamLogs(opts?: {
61
+ signal?: AbortSignal;
62
+ }): AsyncIterable<{
63
+ data: string;
64
+ stream: string;
65
+ }>;
66
+ /** Stop the sandbox. */
67
+ stop(): Promise<void>;
59
68
  }
60
69
  declare function deploySandbox(opts: DeploySandboxOptions): Promise<DeploySandboxResult>;
61
70
 
package/dist/index.js CHANGED
@@ -2936,7 +2936,7 @@ function createAuthMiddleware(token) {
2936
2936
  const cleanUrl = cleanPath + (url.search || "");
2937
2937
  res.setHeader(
2938
2938
  "Set-Cookie",
2939
- `viagen_session=${token}; HttpOnly; SameSite=Lax; Path=/; Secure`
2939
+ `viagen_session=${token}; HttpOnly; SameSite=Lax; Path=/`
2940
2940
  );
2941
2941
  res.writeHead(302, { Location: cleanUrl });
2942
2942
  res.end();
@@ -2948,7 +2948,7 @@ function createAuthMiddleware(token) {
2948
2948
  const cleanUrl = url.pathname + (url.search || "");
2949
2949
  res.setHeader(
2950
2950
  "Set-Cookie",
2951
- `viagen_session=${token}; HttpOnly; SameSite=Lax; Path=/; Secure`
2951
+ `viagen_session=${token}; HttpOnly; SameSite=Lax; Path=/`
2952
2952
  );
2953
2953
  res.writeHead(302, { Location: cleanUrl });
2954
2954
  res.end();
@@ -3538,6 +3538,16 @@ function extractHost(httpsUrl) {
3538
3538
  return "github.com";
3539
3539
  }
3540
3540
  }
3541
+ function startDots(label) {
3542
+ process.stdout.write(label);
3543
+ const timer = setInterval(() => process.stdout.write("."), 1e3);
3544
+ return {
3545
+ stop() {
3546
+ clearInterval(timer);
3547
+ process.stdout.write("\n");
3548
+ }
3549
+ };
3550
+ }
3541
3551
  async function waitForServer(baseUrl, devServer) {
3542
3552
  const timeout = 6e4;
3543
3553
  const start = Date.now();
@@ -3546,13 +3556,7 @@ async function waitForServer(baseUrl, devServer) {
3546
3556
  const logStream = (async () => {
3547
3557
  try {
3548
3558
  for await (const log of devServer.logs({ signal: ac.signal })) {
3549
- const line = log.data;
3550
- serverOutput += line;
3551
- if (log.stream === "stderr") {
3552
- process.stderr.write(` ${line}`);
3553
- } else {
3554
- process.stdout.write(` ${line}`);
3555
- }
3559
+ serverOutput += log.data;
3556
3560
  }
3557
3561
  } catch {
3558
3562
  }
@@ -3706,14 +3710,12 @@ async function deploySandbox(opts) {
3706
3710
  content: Buffer.from(envLines.join("\n"))
3707
3711
  }
3708
3712
  ]);
3709
- console.log(" Installing dependencies...");
3710
- const install = await sandbox.runCommand({
3711
- cmd: "npm",
3712
- args: ["install"],
3713
- stdout: process.stdout,
3714
- stderr: process.stderr
3715
- });
3713
+ const dots = startDots(" Installing dependencies");
3714
+ const install = await sandbox.runCommand("npm", ["install"]);
3715
+ dots.stop();
3716
3716
  if (install.exitCode !== 0) {
3717
+ const stderr = await install.stderr();
3718
+ console.error(stderr);
3717
3719
  throw new Error(`npm install failed (exit ${install.exitCode})`);
3718
3720
  }
3719
3721
  const devServer = await sandbox.runCommand({
@@ -3721,10 +3723,11 @@ async function deploySandbox(opts) {
3721
3723
  args: ["run", "dev", "--", "--host", "0.0.0.0"],
3722
3724
  detached: true
3723
3725
  });
3724
- console.log(" Starting dev server...");
3725
3726
  const baseUrl = sandbox.domain(5173);
3726
3727
  const url = `${baseUrl}/t/${token}`;
3728
+ const dots2 = startDots(" Starting dev server");
3727
3729
  const ready = await waitForServer(baseUrl, devServer);
3730
+ dots2.stop();
3728
3731
  if (!ready.ok) {
3729
3732
  throw new Error(
3730
3733
  `Dev server failed to start: ${ready.error}`
@@ -3734,7 +3737,9 @@ async function deploySandbox(opts) {
3734
3737
  url,
3735
3738
  token,
3736
3739
  sandboxId: sandbox.sandboxId,
3737
- mode: useGit ? "git" : "upload"
3740
+ mode: useGit ? "git" : "upload",
3741
+ streamLogs: (opts2) => devServer.logs(opts2),
3742
+ stop: () => sandbox.stop()
3738
3743
  };
3739
3744
  } catch (err) {
3740
3745
  await sandbox.stop().catch(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viagen",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "description": "Vite dev server plugin that exposes endpoints for chatting with Claude Code SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",