@schuttdev/gigai 0.1.0-beta.12 → 0.1.0-beta.14

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.
@@ -193,13 +193,6 @@ var CloudflareHttpsConfigSchema = z.object({
193
193
  tunnelName: z.string(),
194
194
  domain: z.string().optional()
195
195
  });
196
- var LetsEncryptHttpsConfigSchema = z.object({
197
- provider: z.literal("letsencrypt"),
198
- domain: z.string(),
199
- email: z.string().email(),
200
- certPath: z.string().optional(),
201
- keyPath: z.string().optional()
202
- });
203
196
  var ManualHttpsConfigSchema = z.object({
204
197
  provider: z.literal("manual"),
205
198
  certPath: z.string(),
@@ -208,7 +201,6 @@ var ManualHttpsConfigSchema = z.object({
208
201
  var HttpsConfigSchema = z.discriminatedUnion("provider", [
209
202
  TailscaleHttpsConfigSchema,
210
203
  CloudflareHttpsConfigSchema,
211
- LetsEncryptHttpsConfigSchema,
212
204
  ManualHttpsConfigSchema
213
205
  ]);
214
206
  var CliToolConfigSchema = z.object({
@@ -3,7 +3,7 @@ import {
3
3
  ErrorCode,
4
4
  GigaiError,
5
5
  encrypt
6
- } from "./chunk-4XUWD3DZ.js";
6
+ } from "./chunk-HIKBVSBK.js";
7
7
 
8
8
  // ../server/dist/chunk-54TEF6CS.mjs
9
9
  import { nanoid } from "nanoid";
@@ -5,14 +5,14 @@ import {
5
5
  import {
6
6
  generatePairingCode,
7
7
  validateAndPair
8
- } from "./chunk-FN4LCKUA.js";
8
+ } from "./chunk-HN7WQY7K.js";
9
9
  import {
10
10
  ErrorCode,
11
11
  GigaiConfigSchema,
12
12
  GigaiError,
13
13
  decrypt,
14
14
  generateEncryptionKey
15
- } from "./chunk-4XUWD3DZ.js";
15
+ } from "./chunk-HIKBVSBK.js";
16
16
 
17
17
  // ../server/dist/index.mjs
18
18
  import { parseArgs } from "util";
@@ -41,6 +41,7 @@ import { nanoid } from "nanoid";
41
41
  import { readFile as readFile3 } from "fs/promises";
42
42
  import { resolve as resolve3 } from "path";
43
43
  import { spawn as spawn3 } from "child_process";
44
+ import { spawn as spawn4 } from "child_process";
44
45
  import { input, select, checkbox, confirm } from "@inquirer/prompts";
45
46
  import { writeFile as writeFile2 } from "fs/promises";
46
47
  import { resolve as resolve4 } from "path";
@@ -786,7 +787,9 @@ async function createServer(opts) {
786
787
  trustProxy: !dev
787
788
  // Only trust proxy headers in production (behind HTTPS reverse proxy)
788
789
  });
789
- if (!dev) {
790
+ const httpsProvider = config.server.https?.provider;
791
+ const behindTunnel = httpsProvider === "tailscale" || httpsProvider === "cloudflare";
792
+ if (!dev && !behindTunnel) {
790
793
  server.addHook("onRequest", async (request, _reply) => {
791
794
  if (request.protocol !== "https") {
792
795
  throw new GigaiError(ErrorCode.HTTPS_REQUIRED, "HTTPS is required");
@@ -866,11 +869,26 @@ async function enableFunnel(port) {
866
869
  if (exitCode !== 0) {
867
870
  throw new Error(`Failed to enable Tailscale Funnel: ${stdout}`);
868
871
  }
869
- return `https://${status.hostname}:${port}`;
872
+ return `https://${status.hostname}`;
870
873
  }
871
874
  async function disableFunnel(port) {
872
875
  await runCommand("tailscale", ["funnel", "--bg", "off", `${port}`]);
873
876
  }
877
+ function runTunnel(tunnelName, localPort) {
878
+ const child = spawn4("cloudflared", [
879
+ "tunnel",
880
+ "--url",
881
+ `http://localhost:${localPort}`,
882
+ "run",
883
+ tunnelName
884
+ ], {
885
+ shell: false,
886
+ stdio: "ignore",
887
+ detached: true
888
+ });
889
+ child.unref();
890
+ return child;
891
+ }
874
892
  var execFileAsync = promisify(execFile);
875
893
  async function getTailscaleDnsName() {
876
894
  try {
@@ -890,7 +908,6 @@ async function runInit() {
890
908
  choices: [
891
909
  { name: "Tailscale Funnel (recommended)", value: "tailscale" },
892
910
  { name: "Cloudflare Tunnel", value: "cloudflare" },
893
- { name: "Let's Encrypt", value: "letsencrypt" },
894
911
  { name: "Manual (provide certs)", value: "manual" },
895
912
  { name: "None (dev mode only)", value: "none" }
896
913
  ]
@@ -919,22 +936,6 @@ async function runInit() {
919
936
  };
920
937
  break;
921
938
  }
922
- case "letsencrypt": {
923
- const domain = await input({
924
- message: "Domain name:",
925
- required: true
926
- });
927
- const email = await input({
928
- message: "Email for Let's Encrypt:",
929
- required: true
930
- });
931
- httpsConfig = {
932
- provider: "letsencrypt",
933
- domain,
934
- email
935
- };
936
- break;
937
- }
938
939
  case "manual": {
939
940
  const certPath = await input({
940
941
  message: "Path to TLS certificate:",
@@ -1020,13 +1021,22 @@ async function runInit() {
1020
1021
  await writeFile2(configPath, JSON.stringify(config, null, 2) + "\n", { mode: 384 });
1021
1022
  console.log(`
1022
1023
  Config written to: ${configPath}`);
1023
- let serverUrl = "<YOUR_SERVER_URL>";
1024
+ let serverUrl;
1024
1025
  if (httpsProvider === "tailscale") {
1025
1026
  const dnsName = await getTailscaleDnsName();
1026
1027
  if (dnsName) {
1027
- serverUrl = `https://${dnsName}:${port}`;
1028
+ serverUrl = `https://${dnsName}`;
1028
1029
  console.log(` Detected Tailscale URL: ${serverUrl}`);
1029
1030
  }
1031
+ } else if (httpsProvider === "cloudflare" && httpsConfig && "domain" in httpsConfig && httpsConfig.domain) {
1032
+ serverUrl = `https://${httpsConfig.domain}`;
1033
+ console.log(` Cloudflare URL: ${serverUrl}`);
1034
+ }
1035
+ if (!serverUrl) {
1036
+ serverUrl = await input({
1037
+ message: "Server URL (how clients will reach this server):",
1038
+ required: true
1039
+ });
1030
1040
  }
1031
1041
  const store = new AuthStore();
1032
1042
  const code = generatePairingCode(store, config.auth.pairingTtlSeconds);
@@ -1162,7 +1172,7 @@ async function unwrapTool(name) {
1162
1172
  async function generateServerPairingCode(configPath) {
1163
1173
  const { config } = await loadConfigFile(configPath);
1164
1174
  const { AuthStore: AuthStore2 } = await import("./store-Y4V3TOYJ-GKOB6ANA.js");
1165
- const { generatePairingCode: generatePairingCode2 } = await import("./pairing-IGMDVOIZ-RA7GNFU7.js");
1175
+ const { generatePairingCode: generatePairingCode2 } = await import("./pairing-IGMDVOIZ-SZYYTKV3.js");
1166
1176
  const store = new AuthStore2();
1167
1177
  const code = generatePairingCode2(store, config.auth.pairingTtlSeconds);
1168
1178
  console.log(`
@@ -1187,22 +1197,38 @@ async function startServer() {
1187
1197
  const host = config.server.host;
1188
1198
  await server.listen({ port, host });
1189
1199
  server.log.info(`gigai server listening on ${host}:${port}`);
1190
- if (config.server.https?.provider === "tailscale") {
1200
+ let cfTunnel;
1201
+ const httpsProvider = config.server.https?.provider;
1202
+ if (httpsProvider === "tailscale") {
1191
1203
  try {
1192
1204
  const funnelUrl = await enableFunnel(port);
1193
1205
  server.log.info(`Tailscale Funnel enabled: ${funnelUrl}`);
1194
1206
  } catch (e) {
1195
1207
  server.log.error(`Failed to enable Tailscale Funnel: ${e.message}`);
1196
1208
  }
1209
+ } else if (httpsProvider === "cloudflare") {
1210
+ try {
1211
+ const tunnelName = config.server.https.tunnelName;
1212
+ cfTunnel = runTunnel(tunnelName, port);
1213
+ server.log.info(`Cloudflare Tunnel started: ${tunnelName}`);
1214
+ } catch (e) {
1215
+ server.log.error(`Failed to start Cloudflare Tunnel: ${e.message}`);
1216
+ }
1197
1217
  }
1198
1218
  const shutdown = async () => {
1199
1219
  server.log.info("Shutting down...");
1200
- if (config.server.https?.provider === "tailscale") {
1220
+ if (httpsProvider === "tailscale") {
1201
1221
  try {
1202
1222
  await disableFunnel(port);
1203
1223
  } catch {
1204
1224
  }
1205
1225
  }
1226
+ if (cfTunnel) {
1227
+ try {
1228
+ cfTunnel.kill();
1229
+ } catch {
1230
+ }
1231
+ }
1206
1232
  await server.close();
1207
1233
  process.exit(0);
1208
1234
  };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  decodeJWTPayload
4
- } from "./chunk-4XUWD3DZ.js";
4
+ } from "./chunk-HIKBVSBK.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { defineCommand, runMain } from "citty";
@@ -307,6 +307,25 @@ async function execTool(http, name, args, timeout) {
307
307
  if (res.stderr) process.stderr.write(res.stderr);
308
308
  process.exitCode = res.exitCode;
309
309
  }
310
+ async function execMcpTool(http, tool, mcpTool, args) {
311
+ const res = await http.post("/exec/mcp", {
312
+ tool,
313
+ mcpTool,
314
+ args
315
+ });
316
+ for (const content of res.content) {
317
+ if (content.type === "text" && content.text) {
318
+ process.stdout.write(content.text + "\n");
319
+ } else if (content.type === "image") {
320
+ console.log(`[Image: ${content.mimeType}]`);
321
+ } else if (content.type === "resource") {
322
+ console.log(`[Resource: ${content.mimeType}]`);
323
+ }
324
+ }
325
+ if (res.isError) {
326
+ process.exitCode = 1;
327
+ }
328
+ }
310
329
 
311
330
  // src/transfer.ts
312
331
  import { readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
@@ -408,7 +427,21 @@ if (mode === "client") {
408
427
  try {
409
428
  const { serverUrl, sessionToken } = await connect();
410
429
  const http = createHttpClient(serverUrl, sessionToken);
411
- await execTool(http, toolName, toolArgs);
430
+ const { tool: detail } = await fetchToolDetail(http, toolName);
431
+ if (detail.type === "mcp") {
432
+ const mcpToolName = toolArgs[0];
433
+ if (!mcpToolName) {
434
+ const toolNames = (detail.mcpTools ?? []).map((t) => ` ${t.name} \u2014 ${t.description}`);
435
+ console.log(`MCP tools for ${toolName}:
436
+ ${toolNames.join("\n")}`);
437
+ } else {
438
+ const jsonArg = toolArgs.slice(1).join(" ");
439
+ const args = jsonArg ? JSON.parse(jsonArg) : {};
440
+ await execMcpTool(http, toolName, mcpToolName, args);
441
+ }
442
+ } else {
443
+ await execTool(http, toolName, toolArgs);
444
+ }
412
445
  } catch (e) {
413
446
  console.error(`Error: ${e.message}`);
414
447
  process.exitCode = 1;
@@ -505,7 +538,7 @@ function runCitty() {
505
538
  dev: { type: "boolean", description: "Development mode (no HTTPS)" }
506
539
  },
507
540
  async run({ args }) {
508
- const { startServer } = await import("./dist-6OXWFCEL.js");
541
+ const { startServer } = await import("./dist-EG3MXFDE.js");
509
542
  const extraArgs = [];
510
543
  if (args.config) extraArgs.push("--config", args.config);
511
544
  if (args.dev) extraArgs.push("--dev");
@@ -516,7 +549,7 @@ function runCitty() {
516
549
  init: defineCommand({
517
550
  meta: { name: "init", description: "Interactive setup wizard" },
518
551
  async run() {
519
- const { runInit } = await import("./dist-6OXWFCEL.js");
552
+ const { runInit } = await import("./dist-EG3MXFDE.js");
520
553
  await runInit();
521
554
  }
522
555
  }),
@@ -526,7 +559,7 @@ function runCitty() {
526
559
  config: { type: "string", alias: "c", description: "Config file path" }
527
560
  },
528
561
  async run({ args }) {
529
- const { generateServerPairingCode } = await import("./dist-6OXWFCEL.js");
562
+ const { generateServerPairingCode } = await import("./dist-EG3MXFDE.js");
530
563
  await generateServerPairingCode(args.config);
531
564
  }
532
565
  }),
@@ -553,21 +586,21 @@ function runCitty() {
553
586
  cli: defineCommand({
554
587
  meta: { name: "cli", description: "Wrap a CLI command" },
555
588
  async run() {
556
- const { wrapCli } = await import("./dist-6OXWFCEL.js");
589
+ const { wrapCli } = await import("./dist-EG3MXFDE.js");
557
590
  await wrapCli();
558
591
  }
559
592
  }),
560
593
  mcp: defineCommand({
561
594
  meta: { name: "mcp", description: "Wrap an MCP server" },
562
595
  async run() {
563
- const { wrapMcp } = await import("./dist-6OXWFCEL.js");
596
+ const { wrapMcp } = await import("./dist-EG3MXFDE.js");
564
597
  await wrapMcp();
565
598
  }
566
599
  }),
567
600
  script: defineCommand({
568
601
  meta: { name: "script", description: "Wrap a script" },
569
602
  async run() {
570
- const { wrapScript } = await import("./dist-6OXWFCEL.js");
603
+ const { wrapScript } = await import("./dist-EG3MXFDE.js");
571
604
  await wrapScript();
572
605
  }
573
606
  }),
@@ -577,7 +610,7 @@ function runCitty() {
577
610
  path: { type: "positional", description: "Path to config file", required: true }
578
611
  },
579
612
  async run({ args }) {
580
- const { wrapImport } = await import("./dist-6OXWFCEL.js");
613
+ const { wrapImport } = await import("./dist-EG3MXFDE.js");
581
614
  await wrapImport(args.path);
582
615
  }
583
616
  })
@@ -589,7 +622,7 @@ function runCitty() {
589
622
  name: { type: "positional", description: "Tool name", required: true }
590
623
  },
591
624
  async run({ args }) {
592
- const { unwrapTool } = await import("./dist-6OXWFCEL.js");
625
+ const { unwrapTool } = await import("./dist-EG3MXFDE.js");
593
626
  await unwrapTool(args.name);
594
627
  }
595
628
  });
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  generatePairingCode,
4
4
  validateAndPair
5
- } from "./chunk-FN4LCKUA.js";
6
- import "./chunk-4XUWD3DZ.js";
5
+ } from "./chunk-HN7WQY7K.js";
6
+ import "./chunk-HIKBVSBK.js";
7
7
  export {
8
8
  generatePairingCode,
9
9
  validateAndPair
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schuttdev/gigai",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "gigai": "dist/index.js"