@vosjs/cli 0.12.0 → 0.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.
@@ -3352,6 +3352,27 @@ import { join as join8 } from "path";
3352
3352
 
3353
3353
  // src/plugin/recordingCap.ts
3354
3354
  var HOSTED_RECORDING_CAP_SECONDS = 30 * 60;
3355
+ function parseHostedCap(body) {
3356
+ const limits = body && typeof body === "object" ? body.limits : void 0;
3357
+ const cap = limits?.recordingMaxSeconds;
3358
+ return typeof cap === "number" && Number.isInteger(cap) && cap > 0 ? cap : null;
3359
+ }
3360
+ async function hostedRecordingCap(origin, key, fetchImpl = fetch) {
3361
+ const ctl = new AbortController();
3362
+ const timer = setTimeout(() => ctl.abort(), 2e3);
3363
+ try {
3364
+ const res = await fetchImpl(`${origin.replace(/\/+$/, "")}/api/limits`, {
3365
+ signal: ctl.signal,
3366
+ ...key ? { headers: { authorization: `Bearer ${key}` } } : {}
3367
+ });
3368
+ if (!res.ok) return null;
3369
+ return parseHostedCap(await res.json());
3370
+ } catch {
3371
+ return null;
3372
+ } finally {
3373
+ clearTimeout(timer);
3374
+ }
3375
+ }
3355
3376
  function defaultMaxDurationSeconds() {
3356
3377
  return HOSTED_RECORDING_CAP_SECONDS;
3357
3378
  }
@@ -6656,10 +6677,25 @@ async function loadActions(file) {
6656
6677
  ${errors.join("\n ")}`);
6657
6678
  return raw;
6658
6679
  }
6659
- function maxDurationFlag(flags) {
6660
- const v = numFlag(flags, "max-duration", defaultMaxDurationSeconds());
6661
- if (!(v > 0)) throw new UsageError("--max-duration expects seconds above 0");
6662
- return v;
6680
+ async function maxDuration(flags, r) {
6681
+ if (hasFlag(flags, "max-duration")) {
6682
+ const v = numFlag(flags, "max-duration", defaultMaxDurationSeconds());
6683
+ if (!(v > 0)) throw new UsageError("--max-duration expects seconds above 0");
6684
+ return v;
6685
+ }
6686
+ const origin = platformOrigin({
6687
+ origin: strFlag(flags, "origin"),
6688
+ api: strFlag(flags, "api")
6689
+ });
6690
+ const live = await hostedRecordingCap(
6691
+ origin,
6692
+ resolveCredential(strFlag(flags, "key"))
6693
+ );
6694
+ if (live) return live;
6695
+ r.log(
6696
+ `note: could not read the hosted cap from ${origin}/api/limits; recording up to the built-in ${formatDurationCap(defaultMaxDurationSeconds())}`
6697
+ );
6698
+ return defaultMaxDurationSeconds();
6663
6699
  }
6664
6700
  function strictReason(rec) {
6665
6701
  const parts = [`${rec.skipped.length} skipped step(s)`];
@@ -6692,6 +6728,7 @@ async function cmdRecord(argv) {
6692
6728
  throw new UsageError('no URL \u2014 set "url" in the actions file or pass --url');
6693
6729
  const outDir = resolve6(strFlag(flags, "out") ?? "take");
6694
6730
  const backdrop = await takeBackdrop(flags, r);
6731
+ const maxDurationSeconds = await maxDuration(flags, r);
6695
6732
  if (existsSync10(join14(outDir, "meta.json"))) {
6696
6733
  const { prevDoc, kept } = await prepareReRecord(outDir);
6697
6734
  r.log(
@@ -6705,7 +6742,7 @@ async function cmdRecord(argv) {
6705
6742
  r.log("recording\u2026");
6706
6743
  r.event({ event: "phase", phase: "record" });
6707
6744
  const rec = await recordTake(browser, url, actions, paths, r.log, {
6708
- maxDurationSeconds: maxDurationFlag(flags)
6745
+ maxDurationSeconds
6709
6746
  });
6710
6747
  r.event({ event: "phase", phase: "encode" });
6711
6748
  r.log("encoding\u2026");
@@ -6774,6 +6811,7 @@ async function cmdCreate2(argv) {
6774
6811
  throw new UsageError("--parallel expects an integer between 1 and 16");
6775
6812
  }
6776
6813
  const backdrop = await takeBackdrop(flags, r);
6814
+ const maxDurationSeconds = await maxDuration(flags, r);
6777
6815
  if (existsSync10(join14(outDir, "meta.json"))) {
6778
6816
  const { prevDoc, kept } = await prepareReRecord(outDir);
6779
6817
  r.log(
@@ -6787,7 +6825,7 @@ async function cmdCreate2(argv) {
6787
6825
  r.log("recording\u2026");
6788
6826
  r.event({ event: "phase", phase: "record" });
6789
6827
  const rec = await recordTake(browser, url, actions, paths, r.log, {
6790
- maxDurationSeconds: maxDurationFlag(flags)
6828
+ maxDurationSeconds
6791
6829
  });
6792
6830
  r.event({ event: "phase", phase: "encode" });
6793
6831
  r.log("encoding\u2026");
@@ -7573,4 +7611,4 @@ export {
7573
7611
  convertAgentBrowser,
7574
7612
  run
7575
7613
  };
7576
- //# sourceMappingURL=chunk-DEE2KCDO.js.map
7614
+ //# sourceMappingURL=chunk-6TFKMNSG.js.map