@haex-space/vault-sdk 4.7.0 → 4.8.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.
@@ -1596,22 +1596,45 @@ var ModelsAPI = class {
1596
1596
  * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
1597
1597
  * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
1598
1598
  * until then.
1599
- */
1600
- async runAsync(job) {
1599
+ *
1600
+ * Aborting `signal` asks to cancel the job, which then ends as `cancelled`; a job that had
1601
+ * already ended keeps its actual end. A signal that is already aborted rejects with its reason
1602
+ * and starts no job. If the cancel request fails, the run rejects with that error and the job
1603
+ * keeps running on the host; if it reports an unknown job, the run rejects with an error.
1604
+ */
1605
+ async runAsync(job, options = {}) {
1606
+ const { signal } = options;
1607
+ if (signal?.aborted) throw signal.reason;
1601
1608
  const ended = /* @__PURE__ */ new Map();
1602
1609
  let waiting = null;
1603
1610
  const unsubscribe = this.onCompleted((completion) => {
1604
1611
  if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
1605
1612
  else ended.set(completion.jobId, completion);
1606
1613
  });
1614
+ let detach = () => {
1615
+ };
1607
1616
  try {
1608
1617
  const { jobId } = await this.startAsync(job);
1609
- return await new Promise((resolve) => {
1618
+ return await new Promise((resolve, reject) => {
1610
1619
  const early = ended.get(jobId);
1611
- if (early) resolve(early);
1612
- else waiting = { jobId, resolve };
1620
+ if (early) return resolve(early);
1621
+ waiting = { jobId, resolve };
1622
+ if (!signal) return;
1623
+ const cancel = async () => {
1624
+ try {
1625
+ if (!await this.cancelAsync(jobId)) {
1626
+ reject(new Error("The model job could not be cancelled"));
1627
+ }
1628
+ } catch (error) {
1629
+ reject(error);
1630
+ }
1631
+ };
1632
+ if (signal.aborted) return cancel();
1633
+ signal.addEventListener("abort", cancel, { once: true });
1634
+ detach = () => signal.removeEventListener("abort", cancel);
1613
1635
  });
1614
1636
  } finally {
1637
+ detach();
1615
1638
  unsubscribe();
1616
1639
  }
1617
1640
  }
@@ -2721,6 +2744,11 @@ var PermissionWaiterRegistry = class {
2721
2744
  for (const callback of [...set]) callback(decision);
2722
2745
  }
2723
2746
  };
2747
+ function promptedKey(error) {
2748
+ const details = error.details ?? {};
2749
+ const field = (name) => typeof details[name] === "string" ? details[name] : error[name];
2750
+ return permissionKey(field("resourceType"), field("action"), field("target"));
2751
+ }
2724
2752
  function toDeniedError(error) {
2725
2753
  return { ...error, code: 1002 /* DENIED */ };
2726
2754
  }
@@ -2733,7 +2761,7 @@ async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_D
2733
2761
  if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
2734
2762
  throw error;
2735
2763
  }
2736
- const key = permissionKey(error.resourceType, error.action, error.target);
2764
+ const key = promptedKey(error);
2737
2765
  const times = asked.get(key) ?? 0;
2738
2766
  if (times >= MAX_PERMISSION_RETRIES) throw error;
2739
2767
  asked.set(key, times + 1);