@miosa/sdk 3.2.0 → 3.2.1

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/dist/index.d.ts CHANGED
@@ -7449,6 +7449,13 @@ declare class Sandbox {
7449
7449
  waitUntilReady(options?: {
7450
7450
  timeout?: number;
7451
7451
  stream?: boolean;
7452
+ /**
7453
+ * Require the sandbox to be *command-ready* (exec will succeed) before
7454
+ * resolving `true`, not merely aggregate-`ready`. Defaults to `true` so a
7455
+ * resolved wait guarantees exec won't 409 SANDBOX_NOT_COMMAND_READY. Set
7456
+ * `false` for the legacy aggregate-ready semantics.
7457
+ */
7458
+ requireCommandReady?: boolean;
7452
7459
  }): Promise<boolean>;
7453
7460
  private bootFailedError;
7454
7461
  /** Best-effort final check so an SSE `event: timeout` does not mask a boot failure that just landed. */
package/dist/index.js CHANGED
@@ -168,7 +168,7 @@ var TokenRefreshFailedError = class extends MiosaError {
168
168
  };
169
169
 
170
170
  // src/version.ts
171
- var SDK_VERSION = "3.2.0";
171
+ var SDK_VERSION = "3.2.1";
172
172
  var SDK_USER_AGENT = `@miosa/sdk/${SDK_VERSION}`;
173
173
 
174
174
  // src/http.ts
@@ -8451,6 +8451,36 @@ function encodeContent(content) {
8451
8451
  for (let i = 0; i < bytes.length; i++) bin += String.fromCharCode(bytes[i]);
8452
8452
  return btoa(bin);
8453
8453
  }
8454
+ function generateIdempotencyKey() {
8455
+ const c = globalThis.crypto;
8456
+ if (c && typeof c.randomUUID === "function") return c.randomUUID();
8457
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (ch) => {
8458
+ const r = Math.random() * 16 | 0;
8459
+ const v = ch === "x" ? r : r & 3 | 8;
8460
+ return v.toString(16);
8461
+ });
8462
+ }
8463
+ var PLATFORM_READINESS_COMPONENTS = [
8464
+ "command_agent",
8465
+ "process_control",
8466
+ "resource_contract",
8467
+ "clock",
8468
+ "identity",
8469
+ "durability",
8470
+ "filesystem",
8471
+ "internal_probe"
8472
+ ];
8473
+ function isCommandReady(payload) {
8474
+ if (payload["ready"] === true) return true;
8475
+ const readiness = payload["readiness"];
8476
+ const components = readiness?.["components"] ?? payload["components"] ?? payload["readiness_components"];
8477
+ if (!components || typeof components !== "object") return false;
8478
+ return PLATFORM_READINESS_COMPONENTS.every((name) => {
8479
+ const comp = components[name];
8480
+ const status = typeof comp === "string" ? comp : comp?.status;
8481
+ return status === "ready";
8482
+ });
8483
+ }
8454
8484
  var SANDBOX_TEMPLATE = "miosa-sandbox";
8455
8485
  var SANDBOX_TIER_BY_CPU = {
8456
8486
  1: { size: "xs", memoryMb: 2048 },
@@ -9452,6 +9482,7 @@ var Sandbox = class _Sandbox {
9452
9482
  async waitUntilReady(options = {}) {
9453
9483
  const timeout = options.timeout ?? 30;
9454
9484
  const stream = options.stream ?? true;
9485
+ const requireCommandReady = options.requireCommandReady ?? true;
9455
9486
  if (stream) {
9456
9487
  const sseResult = await this.tryReadinessStream(timeout);
9457
9488
  if (sseResult === true) {
@@ -9467,7 +9498,8 @@ var Sandbox = class _Sandbox {
9467
9498
  while (Date.now() < deadlineMs) {
9468
9499
  try {
9469
9500
  const data = await this.readiness();
9470
- if (data.ready === true || data.status === "ready") {
9501
+ const ready = requireCommandReady ? isCommandReady(data) : data.ready === true || data.status === "ready";
9502
+ if (ready) {
9471
9503
  await this.adoptReadyState();
9472
9504
  return true;
9473
9505
  }
@@ -9643,14 +9675,12 @@ var Sandboxes = class {
9643
9675
  });
9644
9676
  }
9645
9677
  async create(params = {}) {
9646
- const idempotencyKey11 = params.idempotencyKey ?? params.idempotency_key;
9678
+ const idempotencyKey11 = params.idempotencyKey ?? params.idempotency_key ?? generateIdempotencyKey();
9647
9679
  const requestOptions = {
9648
9680
  method: "POST",
9649
- body: createBody(params)
9681
+ body: createBody(params),
9682
+ headers: { "Idempotency-Key": idempotencyKey11 }
9650
9683
  };
9651
- if (idempotencyKey11) {
9652
- requestOptions.headers = { "Idempotency-Key": idempotencyKey11 };
9653
- }
9654
9684
  const data = unwrap48(
9655
9685
  await this.http.request(
9656
9686
  "/sandboxes",