gigadrive 2.11.0 → 2.13.0

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/README.md CHANGED
@@ -36,6 +36,7 @@ gigadrive vm cp vm:<id>:/app/dist ./dist # and out
36
36
  gigadrive vm shell <id> # interactive terminal
37
37
  gigadrive vm ls # running microVMs (--all includes stopped)
38
38
  gigadrive vm extend <id> 1h # stop it one hour from now
39
+ gigadrive vm network <id> --deny-egress # cut its internet while it runs
39
40
  gigadrive vm stop <id> && gigadrive vm rm <id>
40
41
  gigadrive vm images create py-ml --from python:3.13 --wait # custom images (or --dockerfile ./Dockerfile)
41
42
  ```
package/dist/index.cjs CHANGED
@@ -32,7 +32,7 @@ var import_effect31 = require("effect");
32
32
  // package.json
33
33
  var package_default = {
34
34
  name: "gigadrive",
35
- version: "2.11.0",
35
+ version: "2.13.0",
36
36
  repository: {
37
37
  type: "git",
38
38
  url: "https://github.com/Gigadrive/sdk.git",
@@ -3333,29 +3333,32 @@ var withClient = (run) => import_effect24.Effect.gen(function* () {
3333
3333
  return yield* import_effect24.Effect.tryPromise({ try: () => run(client), catch: toApiRequestError });
3334
3334
  });
3335
3335
  var signalOnInterrupt = (signal) => (command, exit) => import_effect24.Exit.isInterrupted(exit) ? import_effect24.Effect.tryPromise(() => command.kill(signal)).pipe(import_effect24.Effect.timeout("2 seconds"), import_effect24.Effect.ignore) : import_effect24.Effect.void;
3336
- var createInput = (flags) => import_effect24.Effect.gen(function* () {
3337
- const env = yield* keyValues("--env", flags.env);
3338
- const metadata = yield* keyValues("--metadata", flags.metadata);
3339
- const timeoutMs = yield* import_effect24.Option.match(flags.timeout, {
3340
- onNone: () => import_effect24.Effect.succeed(void 0),
3341
- onSome: (text) => parseLifetime("--timeout", text)
3342
- });
3343
- if (flags.denyEgress && flags.allowEgress.length > 0) {
3336
+ var checkEgressFlags = (denyEgress, allowEgress) => import_effect24.Effect.gen(function* () {
3337
+ if (denyEgress && allowEgress.length > 0) {
3344
3338
  return yield* new InvalidMicroVmOptionsError({
3345
3339
  message: "--allow-egress cannot be combined with --deny-egress."
3346
3340
  });
3347
3341
  }
3348
- if (flags.allowEgress.length > 32) {
3342
+ if (allowEgress.length > 32) {
3349
3343
  return yield* new InvalidMicroVmOptionsError({ message: "--allow-egress takes at most 32 entries." });
3350
3344
  }
3351
3345
  const network = /^\d{1,3}(\.\d{1,3}){3}\/\d{1,2}$/;
3352
3346
  const domain = /^(\*\.)?([a-z0-9-]+\.)+[a-z0-9-]*[a-z][a-z0-9-]*\.?$/i;
3353
- const badEntry = flags.allowEgress.find((entry) => !network.test(entry.trim()) && !domain.test(entry.trim()));
3347
+ const badEntry = allowEgress.find((entry) => !network.test(entry.trim()) && !domain.test(entry.trim()));
3354
3348
  if (badEntry !== void 0) {
3355
3349
  return yield* new InvalidMicroVmOptionsError({
3356
3350
  message: `--allow-egress must be a domain name such as api.openai.com or *.github.com, or an IPv4 network such as 140.82.112.0/20 (got ${badEntry}).`
3357
3351
  });
3358
3352
  }
3353
+ });
3354
+ var createInput = (flags) => import_effect24.Effect.gen(function* () {
3355
+ const env = yield* keyValues("--env", flags.env);
3356
+ const metadata = yield* keyValues("--metadata", flags.metadata);
3357
+ const timeoutMs = yield* import_effect24.Option.match(flags.timeout, {
3358
+ onNone: () => import_effect24.Effect.succeed(void 0),
3359
+ onSome: (text) => parseLifetime("--timeout", text)
3360
+ });
3361
+ yield* checkEgressFlags(flags.denyEgress, flags.allowEgress);
3359
3362
  const badPort = flags.ports.find((port) => !Number.isInteger(port) || port < 1 || port > 65535);
3360
3363
  if (badPort !== void 0) {
3361
3364
  return yield* new InvalidMicroVmOptionsError({ message: `--port must be between 1 and 65535 (got ${badPort}).` });
@@ -3371,6 +3374,8 @@ var createInput = (flags) => import_effect24.Effect.gen(function* () {
3371
3374
  ...import_effect24.Option.match(flags.memory, { onNone: () => ({}), onSome: (memoryMb) => ({ memoryMb }) }),
3372
3375
  ...import_effect24.Option.match(flags.disk, { onNone: () => ({}), onSome: (diskMb) => ({ diskMb }) }),
3373
3376
  ...timeoutMs !== void 0 ? { timeoutMs } : {},
3377
+ ...flags.pauseOnTimeout ? { onTimeout: "pause" } : {},
3378
+ ...flags.autoResume ? { autoResume: true } : {},
3374
3379
  ...flags.ports.length > 0 ? { ports: [...flags.ports] } : {},
3375
3380
  ...env ? { env } : {},
3376
3381
  ...metadata ? { metadata } : {},
@@ -3378,7 +3383,7 @@ var createInput = (flags) => import_effect24.Effect.gen(function* () {
3378
3383
  network: {
3379
3384
  egress: flags.denyEgress ? "deny" : "allow",
3380
3385
  ...flags.privatePreviews ? { previews: "private" } : {},
3381
- ...flags.allowEgress.length > 0 ? { allow: [...flags.allowEgress] } : {}
3386
+ ...flags.allowEgress.length > 0 ? { allow: flags.allowEgress.map((entry) => entry.trim()) } : {}
3382
3387
  }
3383
3388
  } : {},
3384
3389
  ...import_effect24.Option.match(flags.region, { onNone: () => ({}), onSome: (region) => ({ region }) })
@@ -3450,6 +3455,14 @@ var createCommand = import_cli12.Command.make(
3450
3455
  ),
3451
3456
  import_cli12.Options.repeated
3452
3457
  ),
3458
+ pauseOnTimeout: import_cli12.Options.boolean("pause-on-timeout").pipe(
3459
+ import_cli12.Options.withDescription("Pause the microVM when its timeout ends instead of stopping it")
3460
+ ),
3461
+ autoResume: import_cli12.Options.boolean("auto-resume").pipe(
3462
+ import_cli12.Options.withDescription(
3463
+ "Resume the paused microVM when a command, file call or public preview request reaches it"
3464
+ )
3465
+ ),
3453
3466
  region: import_cli12.Options.text("region").pipe(import_cli12.Options.withDescription("Region to place the microVM in"), import_cli12.Options.optional),
3454
3467
  json: jsonOption2
3455
3468
  },
@@ -3505,6 +3518,36 @@ var getCommand = import_cli12.Command.make(
3505
3518
  for (const line of describeMicroVm(vm)) yield* import_effect24.Console.log(line);
3506
3519
  }).pipe(reportErrors2("get the microVM"))
3507
3520
  ).pipe(import_cli12.Command.withDescription("Show a microVM"));
3521
+ var formatGigabytes = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`;
3522
+ var describeMicroVmMetrics = (metrics) => {
3523
+ const latest = metrics.cpu.at(-1);
3524
+ const peak = metrics.cpu.reduce((max, point) => Math.max(max, point.cpuPercent), 0);
3525
+ return [
3526
+ `CPU (last ${metrics.windowMinutes} min, ${metrics.vcpus} vCPU): ${latest ? `${latest.cpuPercent}% at ${latest.time}, peak ${peak}%` : "no samples"}`,
3527
+ metrics.current ? `Memory: ${formatGigabytes(metrics.current.memoryUsedBytes)} of ${formatGigabytes(metrics.current.memoryTotalBytes)}` : "Memory: unavailable (not running, or no answer)",
3528
+ metrics.current ? `Disk: ${formatGigabytes(metrics.current.diskUsedBytes)} of ${formatGigabytes(metrics.current.diskTotalBytes)}` : "Disk: unavailable (not running, or no answer)"
3529
+ ];
3530
+ };
3531
+ var metricsCommand = import_cli12.Command.make(
3532
+ "metrics",
3533
+ {
3534
+ microvmId: microvmIdArg,
3535
+ window: import_cli12.Options.integer("window").pipe(
3536
+ import_cli12.Options.withDescription("Minutes of CPU history, 1 to 1440 (default: 15)"),
3537
+ import_cli12.Options.optional
3538
+ ),
3539
+ json: jsonOption2
3540
+ },
3541
+ ({ microvmId, window, json }) => import_effect24.Effect.gen(function* () {
3542
+ const apiClient = yield* ApiClientService;
3543
+ const windowMinutes = import_effect24.Option.getOrUndefined(window);
3544
+ const metrics = yield* apiClient.request(
3545
+ (client) => client.microvms.getMetrics(microvmId, windowMinutes === void 0 ? {} : { windowMinutes })
3546
+ );
3547
+ if (json) return yield* import_effect24.Console.log(JSON.stringify(metrics, null, 2));
3548
+ for (const line of describeMicroVmMetrics(metrics)) yield* import_effect24.Console.log(line);
3549
+ }).pipe(reportErrors2("read the microVM metrics"))
3550
+ ).pipe(import_cli12.Command.withDescription("Show a microVM's CPU, memory and disk use"));
3508
3551
  var execInMicroVm = (flags, io = nodeSessionIo()) => import_effect24.Effect.gen(function* () {
3509
3552
  const env = yield* keyValues("--env", flags.env);
3510
3553
  const timeout = yield* optionalDuration("--timeout", flags.timeout);
@@ -3766,6 +3809,46 @@ var extendCommand = import_cli12.Command.make(
3766
3809
  },
3767
3810
  ({ microvmId, duration }) => extendMicroVm(microvmId, duration).pipe(import_effect24.Effect.asVoid, reportErrors2("extend the microVM"))
3768
3811
  ).pipe(import_cli12.Command.withDescription("Set how long a microVM keeps running, counted from now"));
3812
+ var updateMicroVmNetwork = (microvmId, flags) => import_effect24.Effect.gen(function* () {
3813
+ const chosen = [flags.denyEgress, flags.allowEgress.length > 0, flags.allowAllEgress].filter(Boolean).length;
3814
+ if (chosen !== 1) {
3815
+ return yield* new InvalidMicroVmOptionsError({
3816
+ message: "Pass exactly one of --deny-egress, --allow-egress or --allow-all-egress."
3817
+ });
3818
+ }
3819
+ yield* checkEgressFlags(flags.denyEgress, flags.allowEgress);
3820
+ const apiClient = yield* ApiClientService;
3821
+ const vm = yield* apiClient.request(
3822
+ (client) => client.microvms.updateNetwork(
3823
+ microvmId,
3824
+ flags.denyEgress ? { egress: "deny" } : flags.allowEgress.length > 0 ? { egress: "allow", allow: flags.allowEgress.map((entry) => entry.trim()) } : { egress: "allow" }
3825
+ )
3826
+ );
3827
+ const reach = vm.network.egress === "deny" ? "no outbound traffic" : vm.network.allow ? vm.network.allow.join(", ") : "the whole internet";
3828
+ yield* import_effect24.Console.log(`${vm.id} now reaches ${reach}.`);
3829
+ return vm;
3830
+ });
3831
+ var networkCommand = import_cli12.Command.make(
3832
+ "network",
3833
+ {
3834
+ microvmId: microvmIdArg,
3835
+ denyEgress: import_cli12.Options.boolean("deny-egress").pipe(import_cli12.Options.withDescription("Block all outbound network traffic")),
3836
+ allowEgress: import_cli12.Options.text("allow-egress").pipe(
3837
+ import_cli12.Options.withDescription(
3838
+ "Only reach this domain name (api.openai.com, *.github.com for every subdomain) or public IPv4 network (140.82.112.0/20) (repeatable, up to 32)"
3839
+ ),
3840
+ import_cli12.Options.repeated
3841
+ ),
3842
+ allowAllEgress: import_cli12.Options.boolean("allow-all-egress").pipe(
3843
+ import_cli12.Options.withDescription("Reach the whole internet again (private networks stay blocked)")
3844
+ )
3845
+ },
3846
+ ({ microvmId, ...flags }) => updateMicroVmNetwork(microvmId, flags).pipe(import_effect24.Effect.asVoid, reportErrors2("update the microVM network"))
3847
+ ).pipe(
3848
+ import_cli12.Command.withDescription(
3849
+ "Change what a running or paused microVM may reach; connections the new rules no longer allow are closed"
3850
+ )
3851
+ );
3769
3852
  var imagesListCommand = import_cli12.Command.make(
3770
3853
  "ls",
3771
3854
  { app: appOption6, json: jsonOption2 },
@@ -3866,12 +3949,14 @@ var SUBCOMMANDS = [
3866
3949
  createCommand,
3867
3950
  listCommand2,
3868
3951
  getCommand,
3952
+ metricsCommand,
3869
3953
  execCommand,
3870
3954
  shellCommand,
3871
3955
  copyCommand,
3872
3956
  stopCommand,
3873
3957
  removeCommand2,
3874
3958
  extendCommand,
3959
+ networkCommand,
3875
3960
  imagesCommand
3876
3961
  ];
3877
3962
  var microvmsCommand = import_cli12.Command.make("microvms", {}, () => import_effect24.Effect.void).pipe(