@haex-space/vault-sdk 4.5.0 → 4.6.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.
Files changed (49) hide show
  1. package/README.md +40 -0
  2. package/dist/cli/index.mjs.map +1 -1
  3. package/dist/{client-Dw2uH1EM.d.ts → client-CcNhK76M.d.mts} +131 -2
  4. package/dist/{client-D4VYF0bP.d.mts → client-DIvNHfx-.d.ts} +131 -2
  5. package/dist/{config-D_HXjsEV.d.mts → config-P_6DqTHl.d.mts} +2 -1
  6. package/dist/{config-D_HXjsEV.d.ts → config-P_6DqTHl.d.ts} +2 -1
  7. package/dist/index.d.mts +32 -7
  8. package/dist/index.d.ts +32 -7
  9. package/dist/index.js +98 -5
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +95 -5
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/node.d.mts +4 -3
  14. package/dist/node.d.ts +4 -3
  15. package/dist/node.mjs +1 -1
  16. package/dist/node.mjs.map +1 -1
  17. package/dist/nuxt.d.mts +2 -1
  18. package/dist/nuxt.d.ts +2 -1
  19. package/dist/nuxt.js +1 -1
  20. package/dist/nuxt.js.map +1 -1
  21. package/dist/react.d.mts +3 -2
  22. package/dist/react.d.ts +3 -2
  23. package/dist/react.js +94 -5
  24. package/dist/react.js.map +1 -1
  25. package/dist/react.mjs +93 -4
  26. package/dist/react.mjs.map +1 -1
  27. package/dist/runtime/nuxt.plugin.client.d.mts +4 -3
  28. package/dist/runtime/nuxt.plugin.client.d.ts +4 -3
  29. package/dist/runtime/nuxt.plugin.client.js +83 -1
  30. package/dist/runtime/nuxt.plugin.client.js.map +1 -1
  31. package/dist/runtime/nuxt.plugin.client.mjs +83 -1
  32. package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
  33. package/dist/svelte.d.mts +3 -2
  34. package/dist/svelte.d.ts +3 -2
  35. package/dist/svelte.js +94 -5
  36. package/dist/svelte.js.map +1 -1
  37. package/dist/svelte.mjs +93 -4
  38. package/dist/svelte.mjs.map +1 -1
  39. package/dist/{types-CYuW3glJ.d.mts → types-snPkjDCj.d.mts} +10 -1
  40. package/dist/{types-CYuW3glJ.d.ts → types-snPkjDCj.d.ts} +10 -1
  41. package/dist/vite.d.mts +2 -1
  42. package/dist/vite.d.ts +2 -1
  43. package/dist/vue.d.mts +3 -2
  44. package/dist/vue.d.ts +3 -2
  45. package/dist/vue.js +94 -5
  46. package/dist/vue.js.map +1 -1
  47. package/dist/vue.mjs +93 -4
  48. package/dist/vue.mjs.map +1 -1
  49. package/package.json +3 -3
package/dist/react.js CHANGED
@@ -4,13 +4,18 @@ var react = require('react');
4
4
  var sqliteProxy = require('drizzle-orm/sqlite-proxy');
5
5
 
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
9
14
  };
10
15
 
11
- // node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.30_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
16
+ // node_modules/.pnpm/tsup@9.0.0_jiti@2.7.0_postcss@8.5.31_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
12
17
  var init_cjs_shims = __esm({
13
- "node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.30_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js"() {
18
+ "node_modules/.pnpm/tsup@9.0.0_jiti@2.7.0_postcss@8.5.31_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js"() {
14
19
  }
15
20
  });
16
21
 
@@ -450,6 +455,10 @@ var NOTIFICATION_EVENTS = {
450
455
  /** A click on one of this extension's notifications (body or action button). */
451
456
  CLICK: "haextension:notification:click"
452
457
  };
458
+ var MODEL_JOB_EVENTS = {
459
+ /** A job of this frame ended: completed, failed or cancelled. */
460
+ COMPLETED: "haextension:model-job:completed"
461
+ };
453
462
  var EXTERNAL_EVENTS = {
454
463
  /** External request from authorized client */
455
464
  REQUEST: "haextension:external:request",
@@ -776,6 +785,17 @@ var CONTACT_COMMANDS = {
776
785
  photo: "extension_contacts_photo"
777
786
  };
778
787
 
788
+ // src/commands/models.ts
789
+ init_cjs_shims();
790
+ var MODEL_COMMANDS = {
791
+ /** The models the user allowed to this extension, without addresses or keys */
792
+ list: "extension_model_list",
793
+ /** Starts a job; the result follows as an event */
794
+ start: "extension_model_job_start",
795
+ /** Cancels a running job of this frame */
796
+ cancel: "extension_model_job_cancel"
797
+ };
798
+
779
799
  // src/commands/mail.ts
780
800
  init_cjs_shims();
781
801
  var MAIL_COMMANDS = {
@@ -1975,6 +1995,69 @@ var ContactsAPI = class {
1975
1995
  }
1976
1996
  };
1977
1997
 
1998
+ // src/api/models.ts
1999
+ init_cjs_shims();
2000
+ var ModelsAPI = class {
2001
+ constructor(client) {
2002
+ this.client = client;
2003
+ }
2004
+ /** The models the user allowed to this extension; empty without any. */
2005
+ async listAsync() {
2006
+ const answer = await this.client.request(
2007
+ MODEL_COMMANDS.list,
2008
+ {}
2009
+ );
2010
+ return answer.models;
2011
+ }
2012
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
2013
+ async startAsync(job) {
2014
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
2015
+ job
2016
+ });
2017
+ return { jobId: answer.jobId };
2018
+ }
2019
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
2020
+ async cancelAsync(jobId) {
2021
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
2022
+ jobId
2023
+ });
2024
+ return answer.cancelled;
2025
+ }
2026
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
2027
+ onCompleted(handler) {
2028
+ const wrapped = (event) => {
2029
+ const data = event.data;
2030
+ if (data) handler(data);
2031
+ };
2032
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2033
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
2034
+ }
2035
+ /**
2036
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
2037
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
2038
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
2039
+ * until then.
2040
+ */
2041
+ async runAsync(job) {
2042
+ const ended = /* @__PURE__ */ new Map();
2043
+ let waiting = null;
2044
+ const unsubscribe = this.onCompleted((completion) => {
2045
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
2046
+ else ended.set(completion.jobId, completion);
2047
+ });
2048
+ try {
2049
+ const { jobId } = await this.startAsync(job);
2050
+ return await new Promise((resolve) => {
2051
+ const early = ended.get(jobId);
2052
+ if (early) resolve(early);
2053
+ else waiting = { jobId, resolve };
2054
+ });
2055
+ } finally {
2056
+ unsubscribe();
2057
+ }
2058
+ }
2059
+ };
2060
+
1978
2061
  // src/api/mail.ts
1979
2062
  init_cjs_shims();
1980
2063
  var MailAPI = class {
@@ -2931,6 +3014,7 @@ var AI_COMMANDS = {
2931
3014
  init_cjs_shims();
2932
3015
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
2933
3016
  var MAX_PERMISSION_RETRIES = 3;
3017
+ var MAX_PERMISSION_PROMPTS = 8;
2934
3018
  function permissionKey(resourceType, action, target) {
2935
3019
  return `${resourceType}:${action}:${target}`;
2936
3020
  }
@@ -2966,14 +3050,18 @@ function toDeniedError(error) {
2966
3050
  return { ...error, code: 1002 /* DENIED */ };
2967
3051
  }
2968
3052
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
3053
+ const asked = /* @__PURE__ */ new Map();
2969
3054
  for (let attempt = 0; ; attempt++) {
2970
3055
  try {
2971
3056
  return await send();
2972
3057
  } catch (error) {
2973
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
3058
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
2974
3059
  throw error;
2975
3060
  }
2976
3061
  const key = permissionKey(error.resourceType, error.action, error.target);
3062
+ const times = asked.get(key) ?? 0;
3063
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
3064
+ asked.set(key, times + 1);
2977
3065
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
2978
3066
  const outcome = await registry.wait(key, timeoutMs);
2979
3067
  if (outcome === "granted") {
@@ -3042,6 +3130,7 @@ var HaexVaultSdk = class {
3042
3130
  this.shell = new ShellAPI(this);
3043
3131
  this.passwords = new PasswordsAPI(this);
3044
3132
  this.contacts = new ContactsAPI(this);
3133
+ this.models = new ModelsAPI(this);
3045
3134
  this.mail = new MailAPI(this);
3046
3135
  this.notifications = new NotificationsAPI(this);
3047
3136
  this.tab = new TabAPI(this);