@haex-space/vault-sdk 4.7.1 → 4.8.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.
@@ -536,7 +536,8 @@ var FilesystemAPI = class {
536
536
  this.client = client;
537
537
  }
538
538
  /**
539
- * Opens a save file dialog and saves the provided data to the selected location
539
+ * Opens a save file dialog and saves the provided data to the selected location.
540
+ * Waits for the user without the request timeout.
540
541
  * @param data The file data as Uint8Array
541
542
  * @param options Options for the save dialog
542
543
  * @returns The path where the file was saved, or null if cancelled
@@ -550,7 +551,8 @@ var FilesystemAPI = class {
550
551
  defaultPath: options.defaultPath,
551
552
  title: options.title,
552
553
  filters: options.filters
553
- }
554
+ },
555
+ { timeout: null }
554
556
  );
555
557
  return result;
556
558
  }
@@ -670,25 +672,27 @@ var FilesystemAPI = class {
670
672
  );
671
673
  }
672
674
  /**
673
- * Open a folder selection dialog
675
+ * Open a folder selection dialog; waits for the user without the request timeout
674
676
  * @param options Dialog options
675
677
  * @returns Selected folder path, or null if cancelled
676
678
  */
677
679
  async selectFolder(options = {}) {
678
680
  return this.client.request(
679
681
  FILESYSTEM_COMMANDS.selectFolder,
680
- options
682
+ options,
683
+ { timeout: null }
681
684
  );
682
685
  }
683
686
  /**
684
- * Open a file selection dialog
687
+ * Open a file selection dialog; waits for the user without the request timeout
685
688
  * @param options Dialog options
686
689
  * @returns Selected file paths, or null if cancelled
687
690
  */
688
691
  async selectFile(options = {}) {
689
692
  return this.client.request(
690
693
  FILESYSTEM_COMMANDS.selectFile,
691
- options
694
+ options,
695
+ { timeout: null }
692
696
  );
693
697
  }
694
698
  /**
@@ -1598,22 +1602,45 @@ var ModelsAPI = class {
1598
1602
  * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
1599
1603
  * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
1600
1604
  * until then.
1601
- */
1602
- async runAsync(job) {
1605
+ *
1606
+ * Aborting `signal` asks to cancel the job, which then ends as `cancelled`; a job that had
1607
+ * already ended keeps its actual end. A signal that is already aborted rejects with its reason
1608
+ * and starts no job. If the cancel request fails, the run rejects with that error and the job
1609
+ * keeps running on the host; if it reports an unknown job, the run rejects with an error.
1610
+ */
1611
+ async runAsync(job, options = {}) {
1612
+ const { signal } = options;
1613
+ if (signal?.aborted) throw signal.reason;
1603
1614
  const ended = /* @__PURE__ */ new Map();
1604
1615
  let waiting = null;
1605
1616
  const unsubscribe = this.onCompleted((completion) => {
1606
1617
  if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
1607
1618
  else ended.set(completion.jobId, completion);
1608
1619
  });
1620
+ let detach = () => {
1621
+ };
1609
1622
  try {
1610
1623
  const { jobId } = await this.startAsync(job);
1611
- return await new Promise((resolve) => {
1624
+ return await new Promise((resolve, reject) => {
1612
1625
  const early = ended.get(jobId);
1613
- if (early) resolve(early);
1614
- else waiting = { jobId, resolve };
1626
+ if (early) return resolve(early);
1627
+ waiting = { jobId, resolve };
1628
+ if (!signal) return;
1629
+ const cancel = async () => {
1630
+ try {
1631
+ if (!await this.cancelAsync(jobId)) {
1632
+ reject(new Error("The model job could not be cancelled"));
1633
+ }
1634
+ } catch (error) {
1635
+ reject(error);
1636
+ }
1637
+ };
1638
+ if (signal.aborted) return cancel();
1639
+ signal.addEventListener("abort", cancel, { once: true });
1640
+ detach = () => signal.removeEventListener("abort", cancel);
1615
1641
  });
1616
1642
  } finally {
1643
+ detach();
1617
1644
  unsubscribe();
1618
1645
  }
1619
1646
  }