@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.
package/dist/svelte.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorageAPI } from './client-DS-j-fHu.mjs';
1
+ import { S as StorageAPI } from './client-D9zisRb8.mjs';
2
2
  import { HaexVaultSdk } from './index.mjs';
3
3
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
4
4
  import { Readable } from 'svelte/store';
package/dist/svelte.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorageAPI } from './client-DkVe1o-u.js';
1
+ import { S as StorageAPI } from './client-DiqylZ59.js';
2
2
  import { HaexVaultSdk } from './index.js';
3
3
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
4
4
  import { Readable } from 'svelte/store';
package/dist/svelte.js CHANGED
@@ -2043,22 +2043,45 @@ var ModelsAPI = class {
2043
2043
  * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
2044
2044
  * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
2045
2045
  * until then.
2046
- */
2047
- async runAsync(job) {
2046
+ *
2047
+ * Aborting `signal` asks to cancel the job, which then ends as `cancelled`; a job that had
2048
+ * already ended keeps its actual end. A signal that is already aborted rejects with its reason
2049
+ * and starts no job. If the cancel request fails, the run rejects with that error and the job
2050
+ * keeps running on the host; if it reports an unknown job, the run rejects with an error.
2051
+ */
2052
+ async runAsync(job, options = {}) {
2053
+ const { signal } = options;
2054
+ if (signal?.aborted) throw signal.reason;
2048
2055
  const ended = /* @__PURE__ */ new Map();
2049
2056
  let waiting = null;
2050
2057
  const unsubscribe = this.onCompleted((completion) => {
2051
2058
  if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
2052
2059
  else ended.set(completion.jobId, completion);
2053
2060
  });
2061
+ let detach = () => {
2062
+ };
2054
2063
  try {
2055
2064
  const { jobId } = await this.startAsync(job);
2056
- return await new Promise((resolve) => {
2065
+ return await new Promise((resolve, reject) => {
2057
2066
  const early = ended.get(jobId);
2058
- if (early) resolve(early);
2059
- else waiting = { jobId, resolve };
2067
+ if (early) return resolve(early);
2068
+ waiting = { jobId, resolve };
2069
+ if (!signal) return;
2070
+ const cancel = async () => {
2071
+ try {
2072
+ if (!await this.cancelAsync(jobId)) {
2073
+ reject(new Error("The model job could not be cancelled"));
2074
+ }
2075
+ } catch (error) {
2076
+ reject(error);
2077
+ }
2078
+ };
2079
+ if (signal.aborted) return cancel();
2080
+ signal.addEventListener("abort", cancel, { once: true });
2081
+ detach = () => signal.removeEventListener("abort", cancel);
2060
2082
  });
2061
2083
  } finally {
2084
+ detach();
2062
2085
  unsubscribe();
2063
2086
  }
2064
2087
  }
@@ -3091,6 +3114,11 @@ var PermissionWaiterRegistry = class {
3091
3114
  for (const callback of [...set]) callback(decision);
3092
3115
  }
3093
3116
  };
3117
+ function promptedKey(error) {
3118
+ const details = error.details ?? {};
3119
+ const field = (name) => typeof details[name] === "string" ? details[name] : error[name];
3120
+ return permissionKey(field("resourceType"), field("action"), field("target"));
3121
+ }
3094
3122
  function toDeniedError(error) {
3095
3123
  return { ...error, code: 1002 /* DENIED */ };
3096
3124
  }
@@ -3103,7 +3131,7 @@ async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_D
3103
3131
  if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
3104
3132
  throw error;
3105
3133
  }
3106
- const key = permissionKey(error.resourceType, error.action, error.target);
3134
+ const key = promptedKey(error);
3107
3135
  const times = asked.get(key) ?? 0;
3108
3136
  if (times >= MAX_PERMISSION_RETRIES) throw error;
3109
3137
  asked.set(key, times + 1);