trajectories-sh 1.10.0 → 1.10.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/cli.js CHANGED
@@ -81,7 +81,7 @@ async function uploadTrajectoryAction(directory, opts) {
81
81
  Uploading trajectory ${directory} \u2192 ${chalk.cyan(slug)}
82
82
  `));
83
83
  try {
84
- const { uploadJob } = await import("./upload-EHVKRW64.js");
84
+ const { uploadJob } = await import("./upload-IBWVHRL2.js");
85
85
  const result = await uploadJob(directory, {
86
86
  slug,
87
87
  name: opts.name,
@@ -355,8 +355,6 @@ async function uploadJob(dir, opts) {
355
355
  }
356
356
  async function uploadArchive(jobId, dir) {
357
357
  const tar = await import("tar");
358
- const { createReadStream } = await import("fs");
359
- const { ProgressBar } = await import("./progress-H7WNKHDR.js");
360
358
  const tmpArchive = join(tmpdir(), `trajectories-archive-${randomBytes(4).toString("hex")}.tar.gz`);
361
359
  const entries = collectFiles(dir).map((f) => f.relPath);
362
360
  await tar.create(
@@ -371,97 +369,123 @@ async function uploadArchive(jobId, dir) {
371
369
  const archiveSize = statSync(tmpArchive).size;
372
370
  console.log(` Archive: ${(archiveSize / 1024 / 1024).toFixed(1)} MB (gzipped, ${entries.length} entries)`);
373
371
  try {
374
- const urlResp = await apiPost(`/api/cli/push/${jobId}/upload-url`, {});
375
- if (!urlResp.ok) {
376
- throw new Error(`Failed to get archive upload URL: ${await urlResp.text()}`);
377
- }
378
- const { signed_url: signedUrl } = await urlResp.json();
379
- if (!signedUrl) {
380
- throw new Error("Server returned no signed URL for archive upload");
381
- }
382
- let putError = null;
383
- for (let attempt = 0; attempt < 3; attempt++) {
384
- const bar = new ProgressBar({ total: 1, totalBytes: archiveSize, label: "\u2191 archive" });
385
- const stream = createReadStream(tmpArchive);
386
- let bytesSent = 0;
387
- stream.on("data", (chunk) => {
388
- bytesSent += chunk.length;
389
- bar.setBytes(bytesSent);
390
- });
372
+ const maxAttempts = 3;
373
+ let lastError = null;
374
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
375
+ if (attempt > 1) {
376
+ console.log(` Retrying archive upload (attempt ${attempt}/${maxAttempts})\u2026`);
377
+ }
391
378
  try {
392
- const resp = await fetch(signedUrl, {
393
- method: "PUT",
394
- headers: {
395
- "Content-Type": "application/gzip",
396
- "Content-Length": String(archiveSize)
397
- },
398
- // undici accepts Node streams here
399
- body: stream,
400
- duplex: "half",
401
- signal: AbortSignal.timeout(30 * 60 * 1e3)
402
- });
403
- bar.setCount(1);
404
- bar.done();
405
- if (resp.ok) {
406
- putError = null;
407
- break;
379
+ await uploadArchiveOnce(jobId, tmpArchive, archiveSize, entries.length);
380
+ return;
381
+ } catch (e) {
382
+ lastError = e;
383
+ const msg = e?.message ?? String(e);
384
+ if (!/failed to store|extraction failed|extraction timed out/i.test(msg)) {
385
+ throw e;
408
386
  }
409
- putError = `HTTP ${resp.status} ${resp.statusText}`;
410
- try {
411
- const body = await resp.text();
412
- if (body) putError += ` \u2014 ${body.slice(0, 200).replace(/\s+/g, " ")}`;
413
- } catch {
387
+ if (attempt < maxAttempts) {
388
+ console.log(` \u26A0 ${msg}`);
389
+ await sleep(3e3 * attempt);
414
390
  }
415
- } catch (e) {
416
- bar.done();
417
- putError = `fetch error: ${e?.name ?? "Error"} ${e?.message ?? e}`;
418
- }
419
- try {
420
- stream.destroy?.();
421
- } catch {
422
391
  }
423
- if (attempt < 2) await sleep(2e3 * (attempt + 1));
424
- }
425
- if (putError) {
426
- throw new Error(`Archive upload failed: ${putError}`);
427
392
  }
428
- const extractResp = await apiPost(`/api/cli/push/${jobId}/extract`, {});
429
- if (!extractResp.ok) {
430
- throw new Error(`Failed to start extraction: ${await extractResp.text()}`);
393
+ throw lastError instanceof Error ? lastError : new Error(`Archive upload failed after ${maxAttempts} attempts`);
394
+ } finally {
395
+ try {
396
+ unlinkSync(tmpArchive);
397
+ } catch {
431
398
  }
432
- const extractBar = new ProgressBar({ total: entries.length, totalBytes: 0, label: "\u2699 extract" });
433
- const pollStart = Date.now();
434
- const pollTimeoutMs = 30 * 60 * 1e3;
435
- let lastStatus = null;
436
- while (Date.now() - pollStart < pollTimeoutMs) {
437
- await sleep(1500);
438
- const statusResp = await apiGet(`/api/cli/push/${jobId}/extract-status`);
439
- if (!statusResp.ok) {
440
- throw new Error(`Failed to poll extract status: ${await statusResp.text()}`);
399
+ }
400
+ }
401
+ async function uploadArchiveOnce(jobId, archivePath, archiveSize, entryCount) {
402
+ const { createReadStream } = await import("fs");
403
+ const { ProgressBar } = await import("./progress-H7WNKHDR.js");
404
+ const urlResp = await apiPost(`/api/cli/push/${jobId}/upload-url`, {});
405
+ if (!urlResp.ok) {
406
+ throw new Error(`Failed to get archive upload URL: ${await urlResp.text()}`);
407
+ }
408
+ const { signed_url: signedUrl } = await urlResp.json();
409
+ if (!signedUrl) {
410
+ throw new Error("Server returned no signed URL for archive upload");
411
+ }
412
+ let putError = null;
413
+ for (let attempt = 0; attempt < 3; attempt++) {
414
+ const bar = new ProgressBar({ total: 1, totalBytes: archiveSize, label: "\u2191 archive" });
415
+ const stream = createReadStream(archivePath);
416
+ let bytesSent = 0;
417
+ stream.on("data", (chunk) => {
418
+ bytesSent += chunk.length;
419
+ bar.setBytes(bytesSent);
420
+ });
421
+ try {
422
+ const resp = await fetch(signedUrl, {
423
+ method: "PUT",
424
+ headers: {
425
+ "Content-Type": "application/gzip",
426
+ "Content-Length": String(archiveSize)
427
+ },
428
+ // undici accepts Node streams here
429
+ body: stream,
430
+ duplex: "half",
431
+ signal: AbortSignal.timeout(30 * 60 * 1e3)
432
+ });
433
+ bar.setCount(1);
434
+ bar.done();
435
+ if (resp.ok) {
436
+ putError = null;
437
+ break;
441
438
  }
442
- lastStatus = await statusResp.json();
443
- const uploaded = Number(lastStatus?.uploaded ?? 0);
444
- const errors = Number(lastStatus?.errors ?? 0);
445
- extractBar.setCount(uploaded + errors);
446
- if (lastStatus?.status === "done") break;
447
- if (lastStatus?.status === "error") {
448
- throw new Error(`Archive extraction failed: ${lastStatus?.detail ?? "unknown"}`);
439
+ putError = `HTTP ${resp.status} ${resp.statusText}`;
440
+ try {
441
+ const body = await resp.text();
442
+ if (body) putError += ` \u2014 ${body.slice(0, 200).replace(/\s+/g, " ")}`;
443
+ } catch {
449
444
  }
445
+ } catch (e) {
446
+ bar.done();
447
+ putError = `fetch error: ${e?.name ?? "Error"} ${e?.message ?? e}`;
450
448
  }
451
- extractBar.done();
452
- if (!lastStatus || lastStatus.status !== "done") {
453
- throw new Error("Archive extraction timed out");
454
- }
455
- if (lastStatus.errors && lastStatus.errors > 0) {
456
- throw new Error(
457
- `Archive extraction completed but ${lastStatus.errors} file(s) failed to store. Retry the upload or check server logs.`
458
- );
459
- }
460
- } finally {
461
449
  try {
462
- unlinkSync(tmpArchive);
450
+ stream.destroy?.();
463
451
  } catch {
464
452
  }
453
+ if (attempt < 2) await sleep(2e3 * (attempt + 1));
454
+ }
455
+ if (putError) {
456
+ throw new Error(`Archive upload failed: ${putError}`);
457
+ }
458
+ const extractResp = await apiPost(`/api/cli/push/${jobId}/extract`, {});
459
+ if (!extractResp.ok) {
460
+ throw new Error(`Failed to start extraction: ${await extractResp.text()}`);
461
+ }
462
+ const extractBar = new ProgressBar({ total: entryCount, totalBytes: 0, label: "\u2699 extract" });
463
+ const pollStart = Date.now();
464
+ const pollTimeoutMs = 30 * 60 * 1e3;
465
+ let lastStatus = null;
466
+ while (Date.now() - pollStart < pollTimeoutMs) {
467
+ await sleep(1500);
468
+ const statusResp = await apiGet(`/api/cli/push/${jobId}/extract-status`);
469
+ if (!statusResp.ok) {
470
+ throw new Error(`Failed to poll extract status: ${await statusResp.text()}`);
471
+ }
472
+ lastStatus = await statusResp.json();
473
+ const uploaded = Number(lastStatus?.uploaded ?? 0);
474
+ const errors = Number(lastStatus?.errors ?? 0);
475
+ extractBar.setCount(uploaded + errors);
476
+ if (lastStatus?.status === "done") break;
477
+ if (lastStatus?.status === "error") {
478
+ throw new Error(`Archive extraction failed: ${lastStatus?.detail ?? "unknown"}`);
479
+ }
480
+ }
481
+ extractBar.done();
482
+ if (!lastStatus || lastStatus.status !== "done") {
483
+ throw new Error("Archive extraction timed out");
484
+ }
485
+ if (lastStatus.errors && lastStatus.errors > 0) {
486
+ throw new Error(
487
+ `Archive extraction completed but ${lastStatus.errors} file(s) failed to store. Retry the upload or check server logs.`
488
+ );
465
489
  }
466
490
  }
467
491
  async function apiGet(path, timeout = 6e4) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trajectories-sh",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "CLI for uploading trajectory jobs to trajectories.sh",
5
5
  "type": "module",
6
6
  "bin": {