@schuttdev/gigai 0.1.0-beta.11 → 0.1.0-beta.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.
@@ -40,6 +40,7 @@ import { tmpdir } from "os";
40
40
  import { nanoid } from "nanoid";
41
41
  import { readFile as readFile3 } from "fs/promises";
42
42
  import { resolve as resolve3 } from "path";
43
+ import { spawn as spawn3 } from "child_process";
43
44
  import { input, select, checkbox, confirm } from "@inquirer/prompts";
44
45
  import { writeFile as writeFile2 } from "fs/promises";
45
46
  import { resolve as resolve4 } from "path";
@@ -828,6 +829,48 @@ async function loadConfig(path) {
828
829
  const json = JSON.parse(raw);
829
830
  return GigaiConfigSchema.parse(json);
830
831
  }
832
+ function runCommand(command, args) {
833
+ return new Promise((resolve6, reject) => {
834
+ const child = spawn3(command, args, { shell: false, stdio: ["ignore", "pipe", "pipe"] });
835
+ const chunks = [];
836
+ child.stdout.on("data", (chunk) => chunks.push(chunk));
837
+ child.on("error", reject);
838
+ child.on("close", (exitCode) => {
839
+ resolve6({ stdout: Buffer.concat(chunks).toString("utf8").trim(), exitCode: exitCode ?? 1 });
840
+ });
841
+ });
842
+ }
843
+ async function getTailscaleStatus() {
844
+ try {
845
+ const { stdout, exitCode } = await runCommand("tailscale", ["status", "--json"]);
846
+ if (exitCode !== 0) return { online: false };
847
+ const status = JSON.parse(stdout);
848
+ return {
849
+ online: status.BackendState === "Running",
850
+ hostname: status.Self?.DNSName?.replace(/\.$/, "")
851
+ };
852
+ } catch {
853
+ return { online: false };
854
+ }
855
+ }
856
+ async function enableFunnel(port) {
857
+ const status = await getTailscaleStatus();
858
+ if (!status.online || !status.hostname) {
859
+ throw new Error("Tailscale is not running or not connected");
860
+ }
861
+ const { exitCode, stdout } = await runCommand("tailscale", [
862
+ "funnel",
863
+ "--bg",
864
+ `${port}`
865
+ ]);
866
+ if (exitCode !== 0) {
867
+ throw new Error(`Failed to enable Tailscale Funnel: ${stdout}`);
868
+ }
869
+ return `https://${status.hostname}:${port}`;
870
+ }
871
+ async function disableFunnel(port) {
872
+ await runCommand("tailscale", ["funnel", "--bg", "off", `${port}`]);
873
+ }
831
874
  var execFileAsync = promisify(execFile);
832
875
  async function getTailscaleDnsName() {
833
876
  try {
@@ -1144,8 +1187,22 @@ async function startServer() {
1144
1187
  const host = config.server.host;
1145
1188
  await server.listen({ port, host });
1146
1189
  server.log.info(`gigai server listening on ${host}:${port}`);
1190
+ if (config.server.https?.provider === "tailscale") {
1191
+ try {
1192
+ const funnelUrl = await enableFunnel(port);
1193
+ server.log.info(`Tailscale Funnel enabled: ${funnelUrl}`);
1194
+ } catch (e) {
1195
+ server.log.error(`Failed to enable Tailscale Funnel: ${e.message}`);
1196
+ }
1197
+ }
1147
1198
  const shutdown = async () => {
1148
1199
  server.log.info("Shutting down...");
1200
+ if (config.server.https?.provider === "tailscale") {
1201
+ try {
1202
+ await disableFunnel(port);
1203
+ } catch {
1204
+ }
1205
+ }
1149
1206
  await server.close();
1150
1207
  process.exit(0);
1151
1208
  };
package/dist/index.js CHANGED
@@ -505,7 +505,7 @@ function runCitty() {
505
505
  dev: { type: "boolean", description: "Development mode (no HTTPS)" }
506
506
  },
507
507
  async run({ args }) {
508
- const { startServer } = await import("./dist-66IDK7VT.js");
508
+ const { startServer } = await import("./dist-6OXWFCEL.js");
509
509
  const extraArgs = [];
510
510
  if (args.config) extraArgs.push("--config", args.config);
511
511
  if (args.dev) extraArgs.push("--dev");
@@ -516,7 +516,7 @@ function runCitty() {
516
516
  init: defineCommand({
517
517
  meta: { name: "init", description: "Interactive setup wizard" },
518
518
  async run() {
519
- const { runInit } = await import("./dist-66IDK7VT.js");
519
+ const { runInit } = await import("./dist-6OXWFCEL.js");
520
520
  await runInit();
521
521
  }
522
522
  }),
@@ -526,7 +526,7 @@ function runCitty() {
526
526
  config: { type: "string", alias: "c", description: "Config file path" }
527
527
  },
528
528
  async run({ args }) {
529
- const { generateServerPairingCode } = await import("./dist-66IDK7VT.js");
529
+ const { generateServerPairingCode } = await import("./dist-6OXWFCEL.js");
530
530
  await generateServerPairingCode(args.config);
531
531
  }
532
532
  }),
@@ -553,21 +553,21 @@ function runCitty() {
553
553
  cli: defineCommand({
554
554
  meta: { name: "cli", description: "Wrap a CLI command" },
555
555
  async run() {
556
- const { wrapCli } = await import("./dist-66IDK7VT.js");
556
+ const { wrapCli } = await import("./dist-6OXWFCEL.js");
557
557
  await wrapCli();
558
558
  }
559
559
  }),
560
560
  mcp: defineCommand({
561
561
  meta: { name: "mcp", description: "Wrap an MCP server" },
562
562
  async run() {
563
- const { wrapMcp } = await import("./dist-66IDK7VT.js");
563
+ const { wrapMcp } = await import("./dist-6OXWFCEL.js");
564
564
  await wrapMcp();
565
565
  }
566
566
  }),
567
567
  script: defineCommand({
568
568
  meta: { name: "script", description: "Wrap a script" },
569
569
  async run() {
570
- const { wrapScript } = await import("./dist-66IDK7VT.js");
570
+ const { wrapScript } = await import("./dist-6OXWFCEL.js");
571
571
  await wrapScript();
572
572
  }
573
573
  }),
@@ -577,7 +577,7 @@ function runCitty() {
577
577
  path: { type: "positional", description: "Path to config file", required: true }
578
578
  },
579
579
  async run({ args }) {
580
- const { wrapImport } = await import("./dist-66IDK7VT.js");
580
+ const { wrapImport } = await import("./dist-6OXWFCEL.js");
581
581
  await wrapImport(args.path);
582
582
  }
583
583
  })
@@ -589,7 +589,7 @@ function runCitty() {
589
589
  name: { type: "positional", description: "Tool name", required: true }
590
590
  },
591
591
  async run({ args }) {
592
- const { unwrapTool } = await import("./dist-66IDK7VT.js");
592
+ const { unwrapTool } = await import("./dist-6OXWFCEL.js");
593
593
  await unwrapTool(args.name);
594
594
  }
595
595
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schuttdev/gigai",
3
- "version": "0.1.0-beta.11",
3
+ "version": "0.1.0-beta.12",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "gigai": "dist/index.js"