@slicervm/sdk 0.1.8 → 0.1.9

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,8 +36,10 @@ await vm.delete();
36
36
  ## Cold forks
37
37
 
38
38
  A stopped persistent VM can be committed as an immutable disk parent, then
39
- forked into cold-booted children. Fork calls always wait until the child agent
40
- has finalised its guest identity.
39
+ forked into cold-booted children. Fork calls wait for agent readiness and guest
40
+ identity finalisation by default. `wait: 'none'` acknowledges launch only; if
41
+ requested asynchronous finalisation fails, the daemon removes the child rather
42
+ than expose cloned identity or secrets with partially applied policy.
41
43
 
42
44
  ```ts
43
45
  await vm.shutdown();
@@ -47,9 +49,15 @@ const parent = await vm.commit({
47
49
  });
48
50
 
49
51
  const child = await parent.fork({
52
+ wait: 'agent',
50
53
  waitTimeoutSec: 120,
54
+ persistent: false,
55
+ vcpu: 1,
56
+ ramBytes: 512 * 1024 * 1024,
51
57
  network: { allow: [], drop: ['0.0.0.0/0'] },
58
+ tagMode: 'replace',
52
59
  tags: ['job=node-build'],
60
+ secrets: [],
53
61
  });
54
62
 
55
63
  const description = await child.describe();
package/dist/index.cjs CHANGED
@@ -323,7 +323,8 @@ function vmForkFromWire(w) {
323
323
  status: w.status,
324
324
  ...w.parent_status !== void 0 && { parentStatus: w.parent_status },
325
325
  ...w.child_status !== void 0 && { childStatus: w.child_status },
326
- mode: w.mode ?? ""
326
+ mode: w.mode ?? "",
327
+ ...w.persistent !== void 0 && { persistent: w.persistent }
327
328
  };
328
329
  }
329
330
  function vmDescriptionFromWire(w) {
@@ -373,6 +374,31 @@ function secretFromWire(w) {
373
374
  ...w.modified_at !== void 0 && { modifiedAt: w.modified_at }
374
375
  };
375
376
  }
377
+
378
+ // src/fork.ts
379
+ function buildForkRequest(opts) {
380
+ const wait = opts.wait ?? "agent";
381
+ if (wait !== "agent" && wait !== "none") {
382
+ throw new Error(`invalid fork wait mode ${JSON.stringify(wait)}`);
383
+ }
384
+ const query = new URLSearchParams({ wait });
385
+ if (opts.waitTimeoutSec !== void 0 && opts.waitTimeoutSec > 0) {
386
+ query.set("timeout", `${opts.waitTimeoutSec}s`);
387
+ }
388
+ const body = {};
389
+ if (opts.network !== void 0) body.network = opts.network;
390
+ if (opts.tags !== void 0) body.tags = opts.tags;
391
+ if (opts.tagMode !== void 0) body.tag_mode = opts.tagMode;
392
+ if (opts.secrets !== void 0) body.secrets = opts.secrets;
393
+ if (opts.persistent !== void 0) body.persistent = opts.persistent;
394
+ if (opts.fixups !== void 0) body.fixups = opts.fixups;
395
+ if (opts.vcpu !== void 0) body.vcpu = opts.vcpu;
396
+ if (opts.ramBytes !== void 0) body.ram_bytes = opts.ramBytes;
397
+ return {
398
+ query: query.toString(),
399
+ ...Object.keys(body).length > 0 && { body }
400
+ };
401
+ }
376
402
  function looksLikeUnixSocketPath(s) {
377
403
  if (!s) return false;
378
404
  return s.startsWith("/") || s.startsWith("./") || s.startsWith("../") || s.includes("/");
@@ -1098,20 +1124,11 @@ function errMsg(e) {
1098
1124
  }
1099
1125
  async function forkPath(transport, commitId, opts) {
1100
1126
  const id = validateCommitId(commitId);
1101
- const q = new URLSearchParams();
1102
- q.set("wait", "agent");
1103
- if (opts.waitTimeoutSec !== void 0 && opts.waitTimeoutSec > 0) {
1104
- q.set("timeout", `${opts.waitTimeoutSec}s`);
1105
- }
1106
- const query = q.toString() ? `?${q.toString()}` : "";
1107
- const body = opts.network !== void 0 || (opts.tags?.length ?? 0) > 0 ? {
1108
- ...opts.network !== void 0 && { network: opts.network },
1109
- ...(opts.tags?.length ?? 0) > 0 && { tags: opts.tags }
1110
- } : void 0;
1127
+ const request = buildForkRequest(opts);
1111
1128
  const wire = await transport.request(
1112
1129
  "POST",
1113
- `/vm/commits/${encodeURIComponent(id)}/fork${query}`,
1114
- body
1130
+ `/vm/commits/${encodeURIComponent(id)}/fork?${request.query}`,
1131
+ request.body
1115
1132
  );
1116
1133
  return vmForkFromWire(wire);
1117
1134
  }
@@ -1412,18 +1429,11 @@ var CommitsAPI = class {
1412
1429
  }
1413
1430
  async fork(commitId, opts = {}) {
1414
1431
  const id = validateCommitId2(commitId);
1415
- const qs = new URLSearchParams({ wait: "agent" });
1416
- if (opts.waitTimeoutSec !== void 0 && opts.waitTimeoutSec > 0) {
1417
- qs.set("timeout", `${opts.waitTimeoutSec}s`);
1418
- }
1419
- const body = opts.network !== void 0 || (opts.tags?.length ?? 0) > 0 ? {
1420
- ...opts.network !== void 0 && { network: opts.network },
1421
- ...(opts.tags?.length ?? 0) > 0 && { tags: opts.tags }
1422
- } : void 0;
1432
+ const request = buildForkRequest(opts);
1423
1433
  const wire = await this.transport.request(
1424
1434
  "POST",
1425
- `/vm/commits/${encodeURIComponent(id)}/fork?${qs.toString()}`,
1426
- body
1435
+ `/vm/commits/${encodeURIComponent(id)}/fork?${request.query}`,
1436
+ request.body
1427
1437
  );
1428
1438
  return vmForkFromWire(wire);
1429
1439
  }