@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
@@ -23,6 +23,10 @@ var NOTIFICATION_EVENTS = {
23
23
  /** A click on one of this extension's notifications (body or action button). */
24
24
  CLICK: "haextension:notification:click"
25
25
  };
26
+ var MODEL_JOB_EVENTS = {
27
+ /** A job of this frame ended: completed, failed or cancelled. */
28
+ COMPLETED: "haextension:model-job:completed"
29
+ };
26
30
  var EXTERNAL_EVENTS = {
27
31
  /** External request from authorized client */
28
32
  REQUEST: "haextension:external:request",
@@ -326,6 +330,16 @@ var CONTACT_COMMANDS = {
326
330
  photo: "extension_contacts_photo"
327
331
  };
328
332
 
333
+ // src/commands/models.ts
334
+ var MODEL_COMMANDS = {
335
+ /** The models the user allowed to this extension, without addresses or keys */
336
+ list: "extension_model_list",
337
+ /** Starts a job; the result follows as an event */
338
+ start: "extension_model_job_start",
339
+ /** Cancels a running job of this frame */
340
+ cancel: "extension_model_job_cancel"
341
+ };
342
+
329
343
  // src/commands/mail.ts
330
344
  var MAIL_COMMANDS = {
331
345
  /** LIST mailboxes + optional STATUS counts */
@@ -1535,6 +1549,68 @@ var ContactsAPI = class {
1535
1549
  }
1536
1550
  };
1537
1551
 
1552
+ // src/api/models.ts
1553
+ var ModelsAPI = class {
1554
+ constructor(client) {
1555
+ this.client = client;
1556
+ }
1557
+ /** The models the user allowed to this extension; empty without any. */
1558
+ async listAsync() {
1559
+ const answer = await this.client.request(
1560
+ MODEL_COMMANDS.list,
1561
+ {}
1562
+ );
1563
+ return answer.models;
1564
+ }
1565
+ /** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
1566
+ async startAsync(job) {
1567
+ const answer = await this.client.request(MODEL_COMMANDS.start, {
1568
+ job
1569
+ });
1570
+ return { jobId: answer.jobId };
1571
+ }
1572
+ /** Cancels a running job of this frame; `false` when it is unknown or already ended. */
1573
+ async cancelAsync(jobId) {
1574
+ const answer = await this.client.request(MODEL_COMMANDS.cancel, {
1575
+ jobId
1576
+ });
1577
+ return answer.cancelled;
1578
+ }
1579
+ /** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
1580
+ onCompleted(handler) {
1581
+ const wrapped = (event) => {
1582
+ const data = event.data;
1583
+ if (data) handler(data);
1584
+ };
1585
+ this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1586
+ return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
1587
+ }
1588
+ /**
1589
+ * Starts a job and resolves with its end: `completed` with the result, or `failed` or
1590
+ * `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
1591
+ * consent, no fitting model) reject. The end can arrive before the start answers; it is kept
1592
+ * until then.
1593
+ */
1594
+ async runAsync(job) {
1595
+ const ended = /* @__PURE__ */ new Map();
1596
+ let waiting = null;
1597
+ const unsubscribe = this.onCompleted((completion) => {
1598
+ if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
1599
+ else ended.set(completion.jobId, completion);
1600
+ });
1601
+ try {
1602
+ const { jobId } = await this.startAsync(job);
1603
+ return await new Promise((resolve) => {
1604
+ const early = ended.get(jobId);
1605
+ if (early) resolve(early);
1606
+ else waiting = { jobId, resolve };
1607
+ });
1608
+ } finally {
1609
+ unsubscribe();
1610
+ }
1611
+ }
1612
+ };
1613
+
1538
1614
  // src/api/mail.ts
1539
1615
  var MailAPI = class {
1540
1616
  constructor(client) {
@@ -2568,6 +2644,7 @@ var AI_COMMANDS = {
2568
2644
  // src/client/permissionRetry.ts
2569
2645
  var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
2570
2646
  var MAX_PERMISSION_RETRIES = 3;
2647
+ var MAX_PERMISSION_PROMPTS = 8;
2571
2648
  function permissionKey(resourceType, action, target) {
2572
2649
  return `${resourceType}:${action}:${target}`;
2573
2650
  }
@@ -2603,14 +2680,18 @@ function toDeniedError(error) {
2603
2680
  return { ...error, code: 1002 /* DENIED */ };
2604
2681
  }
2605
2682
  async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
2683
+ const asked = /* @__PURE__ */ new Map();
2606
2684
  for (let attempt = 0; ; attempt++) {
2607
2685
  try {
2608
2686
  return await send();
2609
2687
  } catch (error) {
2610
- if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_RETRIES) {
2688
+ if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
2611
2689
  throw error;
2612
2690
  }
2613
2691
  const key = permissionKey(error.resourceType, error.action, error.target);
2692
+ const times = asked.get(key) ?? 0;
2693
+ if (times >= MAX_PERMISSION_RETRIES) throw error;
2694
+ asked.set(key, times + 1);
2614
2695
  log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
2615
2696
  const outcome = await registry.wait(key, timeoutMs);
2616
2697
  if (outcome === "granted") {
@@ -2679,6 +2760,7 @@ var HaexVaultSdk = class {
2679
2760
  this.shell = new ShellAPI(this);
2680
2761
  this.passwords = new PasswordsAPI(this);
2681
2762
  this.contacts = new ContactsAPI(this);
2763
+ this.models = new ModelsAPI(this);
2682
2764
  this.mail = new MailAPI(this);
2683
2765
  this.notifications = new NotificationsAPI(this);
2684
2766
  this.tab = new TabAPI(this);