gigadrive 2.11.0 → 2.12.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.12.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
  },
@@ -3766,6 +3779,46 @@ var extendCommand = import_cli12.Command.make(
3766
3779
  },
3767
3780
  ({ microvmId, duration }) => extendMicroVm(microvmId, duration).pipe(import_effect24.Effect.asVoid, reportErrors2("extend the microVM"))
3768
3781
  ).pipe(import_cli12.Command.withDescription("Set how long a microVM keeps running, counted from now"));
3782
+ var updateMicroVmNetwork = (microvmId, flags) => import_effect24.Effect.gen(function* () {
3783
+ const chosen = [flags.denyEgress, flags.allowEgress.length > 0, flags.allowAllEgress].filter(Boolean).length;
3784
+ if (chosen !== 1) {
3785
+ return yield* new InvalidMicroVmOptionsError({
3786
+ message: "Pass exactly one of --deny-egress, --allow-egress or --allow-all-egress."
3787
+ });
3788
+ }
3789
+ yield* checkEgressFlags(flags.denyEgress, flags.allowEgress);
3790
+ const apiClient = yield* ApiClientService;
3791
+ const vm = yield* apiClient.request(
3792
+ (client) => client.microvms.updateNetwork(
3793
+ microvmId,
3794
+ flags.denyEgress ? { egress: "deny" } : flags.allowEgress.length > 0 ? { egress: "allow", allow: flags.allowEgress.map((entry) => entry.trim()) } : { egress: "allow" }
3795
+ )
3796
+ );
3797
+ const reach = vm.network.egress === "deny" ? "no outbound traffic" : vm.network.allow ? vm.network.allow.join(", ") : "the whole internet";
3798
+ yield* import_effect24.Console.log(`${vm.id} now reaches ${reach}.`);
3799
+ return vm;
3800
+ });
3801
+ var networkCommand = import_cli12.Command.make(
3802
+ "network",
3803
+ {
3804
+ microvmId: microvmIdArg,
3805
+ denyEgress: import_cli12.Options.boolean("deny-egress").pipe(import_cli12.Options.withDescription("Block all outbound network traffic")),
3806
+ allowEgress: import_cli12.Options.text("allow-egress").pipe(
3807
+ import_cli12.Options.withDescription(
3808
+ "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)"
3809
+ ),
3810
+ import_cli12.Options.repeated
3811
+ ),
3812
+ allowAllEgress: import_cli12.Options.boolean("allow-all-egress").pipe(
3813
+ import_cli12.Options.withDescription("Reach the whole internet again (private networks stay blocked)")
3814
+ )
3815
+ },
3816
+ ({ microvmId, ...flags }) => updateMicroVmNetwork(microvmId, flags).pipe(import_effect24.Effect.asVoid, reportErrors2("update the microVM network"))
3817
+ ).pipe(
3818
+ import_cli12.Command.withDescription(
3819
+ "Change what a running or paused microVM may reach; connections the new rules no longer allow are closed"
3820
+ )
3821
+ );
3769
3822
  var imagesListCommand = import_cli12.Command.make(
3770
3823
  "ls",
3771
3824
  { app: appOption6, json: jsonOption2 },
@@ -3872,6 +3925,7 @@ var SUBCOMMANDS = [
3872
3925
  stopCommand,
3873
3926
  removeCommand2,
3874
3927
  extendCommand,
3928
+ networkCommand,
3875
3929
  imagesCommand
3876
3930
  ];
3877
3931
  var microvmsCommand = import_cli12.Command.make("microvms", {}, () => import_effect24.Effect.void).pipe(